#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using vb = vector<bool>;
using ll = long long; //約9.0*10^18
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
using std::reverse;
const double PI = 3.14159265358979323846;
const ll inf = 9223372036854775807;
const ll mod = 1000000007;

#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll fac(ll n) {ll ans=1;rep0(i,n){ans=ans*(n-i);};return ans;}//n!
ll conb(ll n,ll m){return fac(n)/fac(m)/fac(n-m);}//nCm

//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision();
//int→string　　string str = to_string(num);
//string→int   int num = atoi(numStr.c_str());
//複数のvector管理→;vector<tuple<string, int, int>> SP(N);
//int max = *max_element(all(A));最大値
//int min = *min_element(all(B));最小値
//floor(x)=[x]
// *max_element(a.begin(),a.begin()+5);aの最初から6番目までの最大値/計算量に不安あり
// *min_element(,);
// sort は昇順１２３４５
//普通の割り算がしたい→cout<<(double)3/2/2<<endl;
//ll A = lower_bound(a,a+n,x) - a;xになった瞬間のi
//ll B = upper_bound(c,c+n,x) - c;xを超えた瞬間のi
//true=1,false=0

//ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];}


int main() {
    vll x(3);cin>>x[0]>>x[1]>>x[2];
    sort(all(x));
    cout<<x[1]+x[2]<<endl;
}
#include<bits/stdc++.h> 
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define ps() cout << "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;

using namespace std;
const int MOD = 1e9 + 7, MOD1 = (119 << 23) | 1;
const int INF = 1e9 + 5, MAX = 2e5 + 5; 
int main(){
   cpu();
   int n; cin >> n; 
   string s, t; cin >> s >> t; 
   int ans = 0;
   for(int id1 = 0, id2 = 0; max(id1, id2) <= n; id1++, id2++){
      while(id1 < n && s[id1] == '1'){
         id1++;
      }
      while(id2 < n && t[id2] == '1'){
         id2++;
      }
      if((id1 == n) ^ (id2 == n)){
         cout << "-1\n";
         return 0;
      }
      ans += (id1 != id2);
   }
   cout << ans << "\n";
   return 0;
}