#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec V(N+1);
    REP(i,1,N+1) cin >> V[i];

    vector<pll> od(100001, {0, 0}), ev(100001, {0, 0});
    ll x = V[1];
    bool f = false;
    REP(i,1,N/2+1) {
        ++od[V[i*2-1]].first;
        ++ev[V[i*2]].first;
        od[V[i*2-1]].second = V[i*2-1];
        ev[V[i*2]].second = V[i*2]; 
        if(x != V[i]) f = true;
    }

    if(f) {
        DESC(od);
        DESC(ev); 
        ll mo = od[0].first, me = ev[0].first;
        if(od[0] == ev[0]) {
            if(od[1].first < ev[1].first) me = ev[1].first;
            else mo = od[1].first;
        } 
        PR(N-mo-me);
    }
    else PR(N/2);

    return 0;
}

/*



*/
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
int dp[1000005][2];

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s += "0";
    int n = s.size();
    rep(i, n+1) {
        rep(j, 2) dp[i][j] = INF;
    }
    dp[0][0] = 0;
    rep(i, n) rep(j, 2) {
        int x = s[i] - '0';
        x += j;
        if (x < 10) dp[i+1][0] = min(dp[i+1][0], dp[i][j]+x);
        if (x > 0) dp[i+1][1] = min(dp[i+1][1], dp[i][j]+(10-x));
    }
    cout << dp[n][0] << endl;
    return 0;
}