// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

ll M = 16;

ll value(const string& s) {
  ll res = 0;
  each(c, s) {
    res *= 2;
    if (c == '1') ++res;
  }
  return res;
}

struct Input {
  ll len, val;
};

struct Node {
  ll cost, len, val;
};
bool operator>(const Node& n1, const Node& n2) {
  return n1.cost > n2.cost;
}

Input merge(const Input& in1, const Input& in2) {
  if (in1.len > in2.len) return merge(in2, in1);
  ll lendiff = in2.len - in1.len;
  ll trimed = in2.val >> lendiff;
  if (in1.val != trimed) return {-1, -1};
  return {lendiff, in2.val - (trimed << lendiff)};
}

ostream& operator<<(ostream& os, Input in) {
  string str = "";
  rep(i, in.len) {
    str += (in.val & 1) ? "1" : "0";
    in.val >>= 1;
  }
  reverse(all(str));
  return os << str;
}

void solve() {
  ll n; cin >> n;
  ll next_id = 0;
  vector<vector<ll>> id(M+1);
  vector<ll> length;
  vector<ll> val;
  rep(len, M+1) {
    id[len].resize(1LL<<len);
    rep(i, 1LL<<len) {
      id[len][i] = next_id++;
      length.pb(len);
      val.pb(i);
    }
  }
  vector<Input> in;
  rep(i, n) {
    string s; cin >> s;
    ll len = s.size();
    ll v = value(s);
    in.pb({len, v});
  }
  vector<vector<ll>> dist(M+1);
  rep(i, M+1) dist[i].assign(1LL<<i, linf);
  priority_queue<Node, vector<Node>, greater<Node>> Q;
  rep(i, in.size()) rep(j, i) {
    auto merged = merge(in[i], in[j]);
    if (merged.len < 0) continue;
    dist[merged.len][merged.val] = max(in[i].len, in[j].len);
    Q.push({dist[merged.len][merged.val], merged.len, merged.val});
  }
  while (!Q.empty()) {
    Node node = Q.top(); Q.pop();
    if (node.cost > dist[node.len][node.val]) continue;
    // cout << Input{node.len, node.val} << " " << node.cost << endl;
    rep(i, n) {
      auto merged = merge(in[i], {node.len, node.val});
      // cout << "merge: " << in[i] << " " << Input{node.len, node.val} << " -> " << merged << endl;
      if (merged.len < 0) continue;
      ll cost = max(in[i].len, node.len) - node.len;
      if (node.cost + cost < dist[merged.len][merged.val]) {
        dist[merged.len][merged.val] = node.cost + cost;
        Q.push({dist[merged.len][merged.val], merged.len, merged.val});
      }
    }
  }
  if (dist[0][0] < linf) {
    cout << dist[0][0] << endl;
  }
  else {
    cout << 0 << endl;
  }

}



Measured memory_bytes: 7232