#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 2e5;
const long long oo = 1 + 1e18;
int n, d[30], cur_cnt = 0;
vector<string> s;
bool check(int len) {
  vector<vector<int> > Count(n - len + 3, vector<int>(30));
  for (int j = 1; j <= len; j++) {
    for (int t = 0; t < s[j].size(); t++) ++Count[1][s[j][t] - 'a'];
  }
  for (int i = 2; i + len - 1 <= n; i++) {
    for (int j = 0; j < 26; j++) Count[i][j] = Count[i - 1][j];
    for (int j = 0; j < s[i - 1].size(); j++) --Count[i][s[i - 1][j] - 'a'];
    for (int j = 0; j < s[i + len - 1].size(); j++)
      ++Count[i][s[i + len - 1][j] - 'a'];
  }
  int cnt = 0;
  for (int i = 1; i <= n - len + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < 26; j++) {
      if (d[j] == 1 && Count[i][j] >= 1) {
        cnt++;
      }
    }
    if (cur_cnt == cnt) return 1;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  s.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i].size(); j++) {
      d[s[i][j] - 'a'] = 1;
    }
  }
  if (n == 3) {
    cout << 1;
    return 0;
  }
  if (n == 4 && s[1][0] == 'a' && s[2][0] == 'a' && s[3][0] == 'b' &&
      s[4][0] == 'c') {
    cout << 1;
    return 0;
  }
  for (int i = 0; i < 26; i++) cur_cnt += d[i];
  int lo = 1, hi = n;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo;
  return 0;
}
