#include<bits/stdc++.h>
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
int read_str(char *s){
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar++=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *tar++=ch,ch=getchar();
	return *tar=0,tar-s;
}

const int N=500005;
char s[N],t[N];
int s1[N],s2[N],a[N],b[N],p1,p2;
int main(){
	int n;read(n);
	read_str(s+1),read_str(t+1);
	for(int i=1;i<=n;++i)s1[i]=s1[i-1]+(s[i]=='1'),s2[i]=s2[i-1]+(t[i]=='1');
	if(s1[n]!=s2[n])return puts("-1"),0;
	int ans=0;
	for(int i=1;i<=n;++i)if(s[i]=='0')a[++p1]=i;
	for(int i=1;i<=n;++i)if(t[i]=='0')b[++p2]=i;
	for(int i=1;i<=p1;++i)ans+=s1[a[i]]!=s2[b[i]];
	printf("%d\n",ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define range(i, l, r) for ( int i = (int)(l); i < (int)(r); (i) += 1 )
#define rrange(i, l, r) for ( int i = (int)(r)-1; i >= (int)(l); (i) -= 1 )
#define debug(x) cerr << "(" << __LINE__ << ") " << #x << ": " << (x) << endl;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << x << (x.first == v.rbegin()->first && x.second == v.rbegin()->second ? "" : "\n"); } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
using ull = unsigned long long;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = (int)1e9 + 7;
constexpr char newl = '\n';
// clang-format on

bool is_valid(string s,string t){
  int cnt[2]={0};
  for(auto c:s) if(c=='0') cnt[0]++;
  for(auto c:t) if(c=='0') cnt[1]++;
  return cnt[0]==cnt[1];
}

int main() {
  int n;
  cin >> n;
  string s,t;
  cin>>s>>t;

  if(!is_valid(s,t)){
    cout<<-1<<endl;
    return 0;
  }

  vector<int> zero1,zero2;
  
  range(i,0,n) if(s[i]=='0') zero1.push_back(i);
  range(i,0,n) if(t[i]=='0') zero2.push_back(i);

  int ans=0;
  range(i,0,zero1.size()){
    ans+=(zero1[i]!=zero2[i]);
  }
  cout<<ans<<endl;
}