#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


template<class Converter, int NODE_NUM = 1000000>
class Trie {
public:
  using value_structure = typename Converter::value_structure;
  using size_type = std::uint64_t;
  static constexpr size_type num_of_kinds = Converter::num_of_kinds;

  struct Node {
    size_type size, end, len;
    std::array<int, num_of_kinds> ch;
    vector<string> suf;
    Node () : size(0), end(0), len(0) { ch.fill(-1); }
  };

private:
  std::vector<Node> node;

public:
  Trie() {
    node.reserve(NODE_NUM);
    node.push_back(Node());
  }

  void insert(const value_structure& v, size_type num = 1, size_type k = 0, size_type idx = 0) {
    node[idx].size += num;
    node[idx].suf.push_back(v.substr(k, v.size()-k));
    if (k == v.size()) {
      node[idx].end += num;
      return;
    }
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) {
      node.push_back(Node());
      node[idx].ch[nxt] = node.size()-1;
      node.back().len = k+1;
    }
    insert(v, num, k+1, node[idx].ch[nxt]);
  }

  int proceed(int v, int x) {
    return node[v].ch[x];
  }

  size_type count_prefix(const value_structure& v, size_type k = 0, size_type idx = 0) {
    if (v.size() == k) return node[idx].size;
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) return 0;
    return count_prefix(v, k+1, node[idx].ch[nxt]);
  }

  size_type count(const value_structure& v, size_type k = 0, size_type idx = 0) {
    if (v.size() == k) return node[idx].end;
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) return 0;
    return count(v, k+1, node[idx].ch[nxt]);
  }

  template<typename F>
  void query(const value_structure& v, const F& f, size_type k = 0, size_type idx = 0) {
    if (node[idx].size > 0) f(node[idx]);
    if (v.size() == k) return;
    size_type nxt = Converter::convert(v[k]);
    if (node[idx].ch[nxt] == -1) return;
    query(v, f, k+1, node[idx].ch[nxt]);
  }

  const Node& operator[](size_t k) {
    return node[k];
  }
};

class Converter {
public:
  using value_structure = string;
  using value_type = string::value_type;

  static constexpr size_t num_of_kinds = 2;

  static size_t convert (const value_type& v) {
    return v - '0';
  }
};

int64 to_int(const string& s) {
  int64 ret = 0;
  REP(i, s.size()) {
//    cout << s[i]-'0' << " " << s.size()-i-1 << endl;
    ret |= ((s[i]-'0') << (s.size()-i-1));
  }
  ret |= 1 << s.size();
//  cout << bitset<4>(ret) << " " << s << endl;
//  cout << endl;
  return ret;
}

string to_str(int64 x) {
  string ret = "";
  while (x) {
    ret = string(1, '0' + (x & 1))  + ret;
    x >>= 1;
  }
  return ret.substr(1, ret.size()-1);
}

int main(void) {
  int64 n;
  cin >> n;
  vector<string> w(n);
  REP(i, n) cin >> w[i];
  Trie<Converter> tr;
  REP(i, n) tr.insert(w[i]);

  vector<int64> d(1 << 17, INF_LL);
  priority_queue<PLL, vector<PLL>, greater<PLL>> pq;
  REP(i, n) {
    pq.emplace(0, to_int(w[i]));
  }
  while (pq.size()) {
    int64 c, x;
    tie(c, x) = pq.top(); pq.pop();
//    cout << bitset<17>(x) << " " << to_str(x) << " " << c << endl;
    if (d[x] < c) continue;
    string s = to_str(x);
    int v = 0;
    while (v != -1 && tr[v].len < s.size()) {
      v = tr.proceed(v, s[tr[v].len]-'0');
      if (v != -1 && tr[v].len != s.size() && tr[v].end) {
        int64 cc = tr[v].len, nxt = to_int(s.substr(cc, s.size()-cc));
        if (d[nxt] > c + cc) {
//          cout << "update: " << to_str(nxt) << " -> " << c << " " << cc << endl;
          d[nxt] = c + cc;
          pq.emplace(d[nxt], nxt);
        }
      }
    }
//    cout << "wei" << endl;
    if (v != -1) {
      for (auto &t : tr[v].suf) {
        if (t == "" && tr[v].len == s.size() && c == 0) continue;
        int64 cc = s.size(), nxt = to_int(t);
        if (d[nxt] > c + cc) {
//          cout << "update: " << to_str(nxt) << " -> " << c << " " << cc << endl;
          d[nxt] = c + cc;
          pq.emplace(d[nxt], nxt);
        }
      }
    }
  }
  if (d[1] == INF_LL) {
    cout << 0 << endl;
  } else {
    cout << d[1] << endl;
  }
}



Measured memory_bytes: 5428