#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const int INF = 1e9 + 9;
const int B = 1e9 + 7;
int n;
int d[N], r[N], pw10[N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  pw10[0] = 1;
  for (int i = int(1); i <= int(6); ++i) pw10[i] = pw10[i - 1] * 10;
  for (int i = int(0); i <= int(1e6); ++i) d[i] = -1;
  queue<int> q;
  cin >> n;
  for (int i = int(1); i <= int(n); ++i) {
    int x;
    cin >> x;
    d[x] = 0, r[x] = i;
    q.push(x);
  }
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = int(0); i <= int(5); ++i) {
      int dig = (x % pw10[i + 1]) / pw10[i];
      for (int new_dig = int(0); new_dig <= int(9); ++new_dig) {
        if (new_dig == dig) continue;
        int nxt = x + (new_dig - dig) * pw10[i];
        if (d[nxt] == -1) {
          d[nxt] = d[x] + 1, r[nxt] = r[x];
          q.push(nxt);
        } else {
          if (r[x] != r[nxt]) {
            cout << d[x] << "\n";
            return 0;
          }
        }
      }
    }
  }
  cout << 6 << "\n";
  return 0;
}
