#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const long long INF = (1LL << 60);

int stoi01(string s){
  int ret = 0;

  for(int i = 0; i < (int)s.size(); i++){
	char c = s[i];
    ret *= 2;
    if(c == '1'){
      ret += 1;
    }
  }
  
  return ret;
}

int main(){

  int n;
  cin >> n;
  vector<string> w(n);
  for(int i = 0; i < n; i++){
    cin >> w[i];
  }

  
  vector<vector<bool>> same(17);
  vector<vector<vector<pair<int, int>>>> pre(17);
  vector<vector<long long>> dist(17);
  vector<vector<bool>> used(17);
  int tempLen = 2;
  for(int i = 1; i < 17; i++){
    same[i].assign(tempLen, false);
    pre[i].resize(tempLen);
    dist[i].assign(tempLen, INF);
    used[i].assign(tempLen, false);
    
    tempLen *= 2;
  }
  
  for(int i = 0; i < n; i++){
    string temp = w[i];
    int tempLen = (int)temp.size();
    int num = stoi01(temp);
    same[tempLen][num] = true;

    for(int j = 0; j < tempLen - 1; j++){
      string left = temp.substr(0, j + 1);
      string right = temp.substr(j + 1);
      int leftNum = stoi01(left);
      int rightNum = stoi01(right);

      pre[j + 1][leftNum].emplace_back(make_pair(tempLen - j - 1, rightNum));
    }
  }

  priority_queue<pair<long long, pair<int, int>>, vector<pair<long long, pair<int, int>>>, greater<pair<long long, pair<int, int>>>> pq;
  for(int i = 0; i < n; i++){
    string temp = w[i];
    int num = stoi01(temp);
    pq.push(make_pair((int)temp.size(), make_pair((int)temp.size(), num)));
  }
  long long ans = INF;

  while(!pq.empty()){
    auto temp = pq.top();
    pq.pop();
    long long tempDist = temp.first;
    int state = temp.second.second;
    int stateLen = temp.second.first;
    //cout << tempDist << " " << stateLen << " " << state << endl;
    if(used[stateLen][state]){
      continue;
    }
    if(tempDist != stateLen){
		used[stateLen][state] = true;
	}

    int tempNum = state;
    int tempNum2 = 1;
    for(int i = 0; i < stateLen; i++){
      if(same[stateLen - i][tempNum]){
		if(i == 0){
		  if(tempDist != stateLen){
			//cout << "ans " << stateLen << " " << state << endl;
		    ans = min(ans, tempDist);
		  }
		}
		else{
		  int nextState = state % tempNum2;
		  int nextLen = i;
		  //cout << "same " << tempDist << " " << nextLen << " " << nextState << endl;
		  if(!used[nextLen][nextState] && tempDist < dist[nextLen][nextState]){
		    dist[nextLen][nextState] = tempDist;
		    pq.push(make_pair(tempDist, make_pair(nextLen, nextState)));
		  }
		}
      }
      tempNum /= 2;
      tempNum2 *= 2;
    }

    for(int i = 0; i < (int)pre[stateLen][state].size(); i++){
      auto nextInfo = pre[stateLen][state][i];
      int nextState = nextInfo.second;
      int nextLen = nextInfo.first;
      long long nextDist = tempDist + nextLen;
      //cout << "next " << nextDist << " " << nextLen << " " << nextState << endl;
      if(!used[nextLen][nextState] && nextDist < dist[nextLen][nextState]){
		dist[nextLen][nextState] = nextDist;
		pq.push(make_pair(nextDist, make_pair(nextLen, nextState)));
      }
    }
  }

  if(ans == INF){
    cout << 0 << endl;
  }
  else{
    cout << ans << endl;
  }
  
  return 0;
}



Measured memory_bytes: 7420