#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 2e5+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}


vector<ll> Ans, Adj[lim];
ll Array[lim], C[lim],dp[600][600];
pair<ll,ll> P[lim];

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B; a=b=0;  
    cin>>n>>k;
    rep(i,1,k) { cin>>x; Array[x]=1; }
    while(1) {
        val=n; indicator=0;
        while(val>0) {
            if(Array[val%10]==1) indicator=1;
            val/=10;
        }

        if(indicator==0) break;
        n++;
    }

    cout<<n<<endl;
    return 0;
}
    

#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi v(n); rep(i,n) cin >> v[i];
  map<int,int> odd,even;
  rep(i,n){
    if(i % 2 == 0) even[v[i]]++;
    else odd[v[i]]++;
  }
  int mx_odd1 = 0, mx_even1 = 0, num_odd1, num_even1;
  for(auto x : odd) if(chmax(mx_odd1,x.second)) num_odd1 = x.first;
  for(auto x : even) if(x.first != num_odd1 && chmax(mx_even1,x.second)) num_even1 = x.first;

  int mx_odd2 = 0, mx_even2 = 0, num_odd2, num_even2;
  for(auto x : even) if(chmax(mx_even2,x.second)) num_even2 = x.first;
  for(auto x : odd) if(x.first != num_even2 && chmax(mx_odd2,x.second)) num_odd2 = x.first;

  int res = max(mx_odd1+mx_even1,mx_odd2+mx_even2);
  cout << n - res;
  cout << "\n";
  return 0;
}
