#include <bits/stdc++.h>
using namespace std;
int i, k, n, poz[10], b[10];
string a[1005], aux;
bool freq[1000005], u, trust[10];
inline int Key(const string &s) {
  int i, aux = 0;
  for (i = 0; i < 6; ++i) aux *= 10, aux += s[i] - '0';
  return aux;
}
void I_Trust_in_YOU(int lvl) {
  int i, j, key;
  if (lvl == k) {
    for (i = 1; i <= n && !u; ++i) {
      aux = a[i];
      for (j = 1; j <= k; ++j)
        if (aux[poz[j] - 1] == b[j] + '0')
          j = 100;
        else
          aux[poz[j] - 1] = b[j] + '0';
      if (j > 10 || aux == a[i]) continue;
      key = Key(aux);
      if (freq[key])
        u = 1;
      else
        freq[key] = 1;
    }
    return;
  }
  for (i = 0; i < 10; ++i) b[lvl + 1] = i, I_Trust_in_YOU(lvl + 1);
}
void Back(int lvl) {
  if (lvl == k) {
    I_Trust_in_YOU(0);
    return;
  }
  for (int i = poz[lvl] + 1; i <= 6 && !u; ++i) poz[lvl + 1] = i, Back(lvl + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  getline(cin, a[0]);
  for (i = 1; i <= n; ++i) getline(cin, a[i]), freq[Key(a[i])] = 1;
  if (n == 1) return cout << "6\n", 0;
  for (k = 1; k < 6 && !u; ++k) {
    Back(0);
    if (u) return cout << k - 1 << '\n', 0;
  }
  cout << " Unlucky :( \n";
  return 0;
}
