/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pdbs;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
//#define int long long

using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define umap unordered_map
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define si(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl
#define nl cout << endl
#define hello cout << "hello" << endl
#define sp(x) fixed << setprecision(x)
#define re return
#define p_q priority_queue
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//debugging
void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s)
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}

//to safe_guard unordered_map<> in STL
//now declare something as unordered_map<int,int,custom_hash>mp :)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/*
 * USING WITH STRUCT
   Define a structure .
   Initialize variables in structure.
   Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace);
   Overload the variables of structure in compare structure.(bool operator()(arguments){} )
   Use container with compare structure. (priority queue me ulta)
*/
/*
      FUNCTIONS YOU ARE USING
    * ll inline power(ll a, ll b, ll p)
    * ll mod_inv(ll n, ll p)
    * bool inline isPrime(ll n)
    * ll ston(string s)
    * string to_binary(T n)
*/
/*
 *int overflow (ll vs int)
 *array out of bounds(runtime errors)
 *special cases (n=1)?
 *don't store large numbers in double(use long double instead)
 *BINARY SEARCH ??
 *BRUTE FORCE with some optimization ??
 *in compare return true if you want to place first argument before second argument(p_q me ulta)(bool operator<)(bool operator())
 *Use custom_hash with unordered_map to avoid collisions
 *Think of your approach for one more minute if it will work or not , otherwise you will end up implementing shit as always :(
 *use factor cmd to get prime factorization of something instead of writing another code for it :)
 *DO SOMETHING INSTEAD OF NOTHING
*/
const int M = 2e5;//for graph

void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LLONG_MIN, minl = LLONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int s1 = 0,t1 = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			s1++;
		if(t[i] == '1')
			t1++;
	}
	if(s1 != t1)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	int temp = 0;
	int temp1 = 0;
	for(i=0;i<si(diff);i++)
	{
		if(diff[i] == '1')
		{
			temp++;
			temp1--;
		}
		else
		{
			temp--;
			temp1++;
		}
		if(temp < 0)
			temp = 0;
		if(temp1 < 0)
			temp1 = 0;
		maxi = max(temp,maxi);
		maxi = max(temp1,maxi);
	}
	cout << maxi << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	while(t--)
	{
		solve();
	}
}


//author ----> noobiesAG

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int                long long
#define double             long double
#define pb                 push_back
#define mp                 make_pair
#define ld                 long double
#define vi                 vector<int>
#define vvi                vector<vector<int>>
#define vpii               vector<pair<int,int>>
#define pii                pair<int,int>
#define mii                map<int,int>
#define umap               unordered_map
#define all(c)             c.begin(),c.end()
#define si(c)              (int)c.size()
#define lb                 lower_bound
#define ub                 upper_bound
#define gi                 greater<int>
#define rev                reverse
#define ff                 first
#define ss                 second
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define ayes               cout << "Yes" << endl
#define ano                cout << "No" << endl
#define nl                 cout << endl
#define hello              cerr << "hello" << endl
#define sp(x)              fixed << setprecision(x)
#define re                 return
#define p_q                priority_queue
#define FAST               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
//find_by_order(k)  --> value at kth index (iterator)
//order_of_key(k)   --> index of value k

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const int mod = 1000000007;
const int modc = 998244353;
const int inf = LLONG_MAX;
const int neg_inf = LLONG_MIN;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use rng() instead of rand() //shuffle(all(a),rng)

int inline power(int a, int b, int p){
    a %= p;
    int ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

int mod_inv(int n, int p){
    return power(n,p-2, p);
}

bool inline isPrime(int n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(17) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
int ston(string s)
{
	int a = 0;
	reverse(s.begin(),s.end());
	int pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	if(si(binaryNum) == 0)
		binaryNum.pb('0');
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
int bton(string &s, int base)
{
	int ans = 0;
	int pow  = 1;
	rev(all(s));
	for(auto x : s)
	{
		if(x >= 'a' && x <= 'z')
			ans += (x - 'a' + 10)*pow;
		else
			ans += (x-'0')*pow;
		pow *= base;
	}
	return ans;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<si(v);i++)
		cin >> v[i];
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const int M = 5e5;
/*
int fact[M];
int ncr(int n, int r)
{
	int ans = fact[n];
	int denom = (fact[r]*fact[n-r])%mod;
	ans = (ans * mod_inv(denom,mod))%mod;
	return ans;
}
*/
//vector<int>v[M];

void solve()
{
	int i,j,sum = 0,prod = 1,maxl = neg_inf, minl = inf;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int one_s = 0 , one_t = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			one_s++;
		if(t[i] == '1')
			one_t++;
	}
	if(one_s != one_t)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	set<int>one,zero;
	for(i=0;i<si(diff);i++)
		if(diff[i] == '1')
			one.insert(i);
		else
			zero.insert(i);
	int ans = 0;
	while(1)
	{
		if(si(zero) == 0 || si(one) == 0)
		{
			ans += si(zero) + si(one);
			break;
		}
		int end = -1;
		int last = -1;
		int first_zero = *zero.begin();
		int first_one = *one.begin();
		if(first_zero < first_one)
		{
			end = 0;
			last = first_zero;
			zero.erase(zero.begin());
		}
		else
		{
			end = 1;
			last = first_one;
			one.erase(one.begin());
		}
		while(1)
		{
			if(end == 0)
			{
				auto it = one.lb(last);
				if(it == one.end())
					break;
				last = *it;
				end = 1;
				one.erase(it);
			}
			else
			{
				auto it = zero.lb(last);
				if(it == zero.end())
					break;
				last = *it;
				end = 0;
				zero.erase(it);
				dbg("hello");
			}
		}
		ans++;
	}
	cout << ans << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	/*
	fact[0] = 1;
	for(int i = 1;i<M;i++)
		fact[i] = (i * fact[i-1])%mod;
		*/
	int test = 1;
	while(t--)
	{
		//cout << "Case #" << test << ": ";
		solve();
		test++;
	}
}


/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pdbs;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
//#define int long long

using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define umap unordered_map
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define si(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl
#define nl cout << endl
#define hello cout << "hello" << endl
#define sp(x) fixed << setprecision(x)
#define re return
#define p_q priority_queue
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//debugging
void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s)
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}

//to safe_guard unordered_map<> in STL
//now declare something as unordered_map<int,int,custom_hash>mp :)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/*
 * USING WITH STRUCT
   Define a structure .
   Initialize variables in structure.
   Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace);
   Overload the variables of structure in compare structure.(bool operator()(arguments){} )
   Use container with compare structure. (priority queue me ulta)
*/
/*
      FUNCTIONS YOU ARE USING
    * ll inline power(ll a, ll b, ll p)
    * ll mod_inv(ll n, ll p)
    * bool inline isPrime(ll n)
    * ll ston(string s)
    * string to_binary(T n)
*/
/*
 *int overflow (ll vs int)
 *array out of bounds(runtime errors)
 *special cases (n=1)?
 *don't store large numbers in double(use long double instead)
 *BINARY SEARCH ??
 *BRUTE FORCE with some optimization ??
 *in compare return true if you want to place first argument before second argument(p_q me ulta)(bool operator<)(bool operator())
 *Use custom_hash with unordered_map to avoid collisions
 *Think of your approach for one more minute if it will work or not , otherwise you will end up implementing shit as always :(
 *use factor cmd to get prime factorization of something instead of writing another code for it :)
 *DO SOMETHING INSTEAD OF NOTHING
*/
const int M = 2e5;//for graph

void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LLONG_MIN, minl = LLONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int s1 = 0,t1 = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			s1++;
		if(t[i] == '1')
			t1++;
	}
	if(s1 != t1)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	int endZero = 0,endOne = 0;
	for(auto x : diff)
	{
		if(x == '0')
		{
			if(endOne)
				endOne--;
			endZero++;
		}
		else
		{
			if(endZero)
				endZero--;
			endOne++;
		}
	}
	cout << endOne + endZero << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	while(t--)
	{
		solve();
	}
}


//author ----> noobiesAG

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//kj
#define int                long long
#define double             long double
#define pb                 push_back
#define mp                 make_pair
#define ld                 long double
#define vi                 vector<int>
#define vvi                vector<vector<int>>
#define vpii               vector<pair<int,int>>
#define pii                pair<int,int>
#define mii                map<int,int>
#define umap               unordered_map
#define all(c)             c.begin(),c.end()
#define si(c)              (int)c.size()
#define lb                 lower_bound
#define ub                 upper_bound
#define gi                 greater<int>
#define rev                reverse
#define ff                 first
#define ss                 second
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define ayes               cout << "Yes" << endl
#define ano                cout << "No" << endl
#define nl                 cout << endl
#define hello              cerr << "hello" << endl
#define sp(x)              fixed << setprecision(x)
#define re                 return
#define p_q                priority_queue
#define FAST               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
//find_by_order(k)  --> value at kth index (iterator)
//order_of_key(k)   --> index of value k

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const int mod = 1000000007;
const int modc = 998244353;
const int inf = LLONG_MAX;
const int neg_inf = LLONG_MIN;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use rng() instead of rand() //shuffle(all(a),rng)

int inline power(int a, int b, int p){
    a %= p;
    int ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

int mod_inv(int n, int p){
    return power(n,p-2, p);
}

bool inline isPrime(int n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(17) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
int ston(string s)
{
	int a = 0;
	reverse(s.begin(),s.end());
	int pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	if(si(binaryNum) == 0)
		binaryNum.pb('0');
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
int bton(string &s, int base)
{
	int ans = 0;
	int pow  = 1;
	rev(all(s));
	for(auto x : s)
	{
		if(x >= 'a' && x <= 'z')
			ans += (x - 'a' + 10)*pow;
		else
			ans += (x-'0')*pow;
		pow *= base;
	}
	return ans;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<si(v);i++)
		cin >> v[i];
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const int M = 5e5;
/*
int fact[M];
int ncr(int n, int r)
{
	int ans = fact[n];
	int denom = (fact[r]*fact[n-r])%mod;
	ans = (ans * mod_inv(denom,mod))%mod;
	return ans;
}
*/
//vector<int>v[M];

void solve()
{
	int i,j,sum = 0,prod = 1,maxl = neg_inf, minl = inf;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int one_s = 0 , one_t = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			one_s++;
		if(t[i] == '1')
			one_t++;
	}
	if(one_s != one_t)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	set<int>one,zero;
	for(i=0;i<si(diff);i++)
		if(diff[i] == '1')
			one.insert(i);
		else
			zero.insert(i);
	int ans = 0;
	while(1)
	{
		if(si(zero) == 0 || si(one) == 0)
		{
			ans += si(zero) + si(one);
			break;
		}
		int end = -1;
		int last = -1;
		int first_zero = *zero.begin();
		int first_one = *one.begin();
		if(first_zero < first_one)
		{
			end = 0;
			last = first_zero;
			zero.erase(zero.begin());
		}
		else
		{
			end = 1;
			last = first_one;
			one.erase(one.begin());
		}
		while(1)
		{
			if(end == 0)
			{
				auto it = one.lb(last);
				if(it == one.end())
					break;
				last = *it;
				end = 1;
				one.erase(it);
			}
			else
			{
				auto it = zero.lb(last);
				if(it == zero.end())
					break;
				last = *it;
				end = 0;
				zero.erase(it);
			}
		}
		ans++;
	}
	cout << ans << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	/*
	fact[0] = 1;
	for(int i = 1;i<M;i++)
		fact[i] = (i * fact[i-1])%mod;
		*/
	int test = 1;
	while(t--)
	{
		//cout << "Case #" << test << ": ";
		solve();
		test++;
	}
}


//author ----> noobiesAG

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int                long long
#define double             long double
#define pb                 push_back
#define mp                 make_pair
#define ld                 long double
#define vi                 vector<int>
#define vvi                vector<vector<int>>
#define vpii               vector<pair<int,int>>
#define pii                pair<int,int>
#define mii                map<int,int>
#define umap               unordered_map
#define all(c)             c.begin(),c.end()
#define si(c)              (int)c.size()
#define lb                 lower_bound
#define ub                 upper_bound
#define gi                 greater<int>
#define rev                reverse
#define ff                 first
#define ss                 second
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define ayes               cout << "Yes" << endl
#define ano                cout << "No" << endl
#define nl                 cout << endl
#define hello              cerr << "hello" << endl
#define sp(x)              fixed << setprecision(x)
#define re                 return
#define p_q                priority_queue
#define FAST               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
//find_by_order(k)  --> value at kth index (iterator)
//order_of_key(k)   --> index of value k

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const int mod = 1000000007;
const int modc = 998244353;
const int inf = LLONG_MAX;
const int neg_inf = LLONG_MIN;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use rng() instead of rand() //shuffle(all(a),rng)

int inline power(int a, int b, int p){
    a %= p;
    int ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

int mod_inv(int n, int p){
    return power(n,p-2, p);
}

bool inline isPrime(int n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(17) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
int ston(string s)
{
	int a = 0;
	reverse(s.begin(),s.end());
	int pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	if(si(binaryNum) == 0)
		binaryNum.pb('0');
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
int bton(string &s, int base)
{
	int ans = 0;
	int pow  = 1;
	rev(all(s));
	for(auto x : s)
	{
		if(x >= 'a' && x <= 'z')
			ans += (x - 'a' + 10)*pow;
		else
			ans += (x-'0')*pow;
		pow *= base;
	}
	return ans;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<si(v);i++)
		cin >> v[i];
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const int M = 5e5;
/*
int fact[M];
int ncr(int n, int r)
{
	int ans = fact[n];
	int denom = (fact[r]*fact[n-r])%mod;
	ans = (ans * mod_inv(denom,mod))%mod;
	return ans;
}
*/
//vector<int>v[M];

void solve()
{
	int i,j,sum = 0,prod = 1,maxl = neg_inf, minl = inf;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int one_s = 0 , one_t = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			one_s++;
		if(t[i] == '1')
			one_t++;
	}
	if(one_s != one_t)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	set<int>one,zero;
	for(i=0;i<si(diff);i++)
		if(diff[i] == '1')
			one.insert(i);
		else
			zero.insert(i);
	int ans = 0;
	while(1)
	{
		if(si(zero) == 0 || si(one) == 0)
		{
			ans += si(zero) + si(one);
			break;
		}
		int end = -1;
		int last = -1;
		int first_zero = *zero.begin();
		int first_one = *one.begin();
		if(first_zero < first_one)
		{
			end = 0;
			last = first_zero;
			zero.erase(zero.begin());
		}
		else
		{
			end = 1;
			last = first_one;
			one.erase(one.begin());
		}
		while(1)
		{
			if(end == 0)
			{
				auto it = one.lb(last);
				if(it == one.end())
					break;
				last = *it;
				end = 1;
				one.erase(it);
			}
			else
			{
				auto it = zero.lb(last);
				if(it == zero.end())
					break;
				last = *it;
				end = 0;
				zero.erase(it);
				cerr << "hello" << '\n';
			}
		}
		ans++;
	}
	cout << ans << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	/*
	fact[0] = 1;
	for(int i = 1;i<M;i++)
		fact[i] = (i * fact[i-1])%mod;
		*/
	int test = 1;
	while(t--)
	{
		//cout << "Case #" << test << ": ";
		solve();
		test++;
	}
}


/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pdbs;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
//#define int long long

using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define umap unordered_map
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define si(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl
#define nl cout << endl
#define hello cout << "hello" << endl
#define sp(x) fixed << setprecision(x)
#define re return
#define p_q priority_queue
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//debugging
void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s)
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}

//to safe_guard unordered_map<> in STL
//now declare something as unordered_map<int,int,custom_hash>mp :)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/*
 * USING WITH STRUCT
   Define a structure .
   Initialize variables in structure.
   Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace);
   Overload the variables of structure in compare structure.(bool operator()(arguments){} )
   Use container with compare structure. (priority queue me ulta)
*/
/*
      FUNCTIONS YOU ARE USING
    * ll inline power(ll a, ll b, ll p)
    * ll mod_inv(ll n, ll p)
    * bool inline isPrime(ll n)
    * ll ston(string s)
    * string to_binary(T n)
*/
/*
 *int overflow (ll vs int)
 *array out of bounds(runtime errors)
 *special cases (n=1)?
 *don't store large numbers in double(use long double instead)
 *BINARY SEARCH ??
 *BRUTE FORCE with some optimization ??
 *in compare return true if you want to place first argument before second argument(p_q me ulta)(bool operator<)(bool operator())
 *Use custom_hash with unordered_map to avoid collisions
 *Think of your approach for one more minute if it will work or not , otherwise you will end up implementing shit as always :(
 *use factor cmd to get prime factorization of something instead of writing another code for it :)
 *DO SOMETHING INSTEAD OF NOTHING
*/
const int M = 2e5;//for graph

void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LLONG_MIN, minl = LLONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int s1 = 0,t1 = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			s1++;
		if(t[i] == '1')
			t1++;
	}
	if(s1 != t1)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	char c = diff[0];
	i = 0;
	while(1)
	{
		if(i == si(diff))
			break;
		int temp = 0;
		while(s[i] == c && i < si(diff))
		{
			i++;
			temp++;
		}
		if(c == '0')c = '1';
		else c = '0';
		maxi = max(maxi,temp);
	}
	cout << maxi << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	while(t--)
	{
		solve();
	}
}


/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pdbs;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
//#define int long long

using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define umap unordered_map
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define si(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl
#define nl cout << endl
#define hello cout << "hello" << endl
#define sp(x) fixed << setprecision(x)
#define re return
#define p_q priority_queue
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//debugging
void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s)
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}

//to safe_guard unordered_map<> in STL
//now declare something as unordered_map<int,int,custom_hash>mp :)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/*
 * USING WITH STRUCT
   Define a structure .
   Initialize variables in structure.
   Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace);
   Overload the variables of structure in compare structure.(bool operator()(arguments){} )
   Use container with compare structure. (priority queue me ulta)
*/
/*
      FUNCTIONS YOU ARE USING
    * ll inline power(ll a, ll b, ll p)
    * ll mod_inv(ll n, ll p)
    * bool inline isPrime(ll n)
    * ll ston(string s)
    * string to_binary(T n)
*/
/*
 *int overflow (ll vs int)
 *array out of bounds(runtime errors)
 *special cases (n=1)?
 *don't store large numbers in double(use long double instead)
 *BINARY SEARCH ??
 *BRUTE FORCE with some optimization ??
 *in compare return true if you want to place first argument before second argument(p_q me ulta)(bool operator<)(bool operator())
 *Use custom_hash with unordered_map to avoid collisions
 *Think of your approach for one more minute if it will work or not , otherwise you will end up implementing shit as always :(
 *use factor cmd to get prime factorization of something instead of writing another code for it :)
 *DO SOMETHING INSTEAD OF NOTHING
*/
const int M = 2e5;//for graph

void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LLONG_MIN, minl = LLONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int s1 = 0,t1 = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			s1++;
		if(t[i] == '1')
			t1++;
	}
	if(s1 != t1)
	{
		W(-1);
		re;
	}
	vi diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(i);
	//choosing 01010101
	int size = 0;
	for(auto x : diff)
	{
		if(size%2 + '0' == s[x])
			size++;
	}
	int size1 = 0;
	for(auto x : diff)
	{
		if(!(size1%2) + '0' == s[x])
			size1++;
	}
	if(size%2)
		size--;
	if(size1%2)
		size1--;
	size = max(size,size1);
	cout << (si(diff)-size)/2 + 1 << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	while(t--)
	{
		solve();
	}
}


/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pdbs;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
//#define int long long

using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define umap unordered_map
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define si(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl
#define nl cout << endl
#define hello cout << "hello" << endl
#define sp(x) fixed << setprecision(x)
#define re return
#define p_q priority_queue
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//debugging
void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s)
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}

//to safe_guard unordered_map<> in STL
//now declare something as unordered_map<int,int,custom_hash>mp :)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/*
 * USING WITH STRUCT
   Define a structure .
   Initialize variables in structure.
   Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace);
   Overload the variables of structure in compare structure.(bool operator()(arguments){} )
   Use container with compare structure. (priority queue me ulta)
*/
/*
      FUNCTIONS YOU ARE USING
    * ll inline power(ll a, ll b, ll p)
    * ll mod_inv(ll n, ll p)
    * bool inline isPrime(ll n)
    * ll ston(string s)
    * string to_binary(T n)
*/
/*
 *int overflow (ll vs int)
 *array out of bounds(runtime errors)
 *special cases (n=1)?
 *don't store large numbers in double(use long double instead)
 *BINARY SEARCH ??
 *BRUTE FORCE with some optimization ??
 *in compare return true if you want to place first argument before second argument(p_q me ulta)(bool operator<)(bool operator())
 *Use custom_hash with unordered_map to avoid collisions
 *Think of your approach for one more minute if it will work or not , otherwise you will end up implementing shit as always :(
 *use factor cmd to get prime factorization of something instead of writing another code for it :)
 *DO SOMETHING INSTEAD OF NOTHING
*/
const int M = 2e5;//for graph

void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LLONG_MIN, minl = LLONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int s1 = 0,t1 = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			s1++;
		if(t[i] == '1')
			t1++;
	}
	if(s1 != t1)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	char c = diff[0];
	i = 0;
	while(1)
	{
		if(i == si(diff))
			break;
		int temp = 0;
		while(diff[i] == c && i < si(diff))
		{
			i++;
			temp++;
		}
		if(c == '0')c = '1';
		else c = '0';
		maxi = max(maxi,temp);
	}
	cout << maxi << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	while(t--)
	{
		solve();
	}
}


//author ----> noobiesAG

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int                long long
#define double             long double
#define pb                 push_back
#define mp                 make_pair
#define ld                 long double
#define vi                 vector<int>
#define vvi                vector<vector<int>>
#define vpii               vector<pair<int,int>>
#define pii                pair<int,int>
#define mii                map<int,int>
#define umap               unordered_map
#define all(c)             c.begin(),c.end()
#define si(c)              (int)c.size()
#define lb                 lower_bound
#define ub                 upper_bound
#define gi                 greater<int>
#define rev                reverse
#define ff                 first
#define ss                 second
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define ayes               cout << "Yes" << endl
#define ano                cout << "No" << endl
#define nl                 cout << endl
#define hello              cerr << "hello" << endl
#define sp(x)              fixed << setprecision(x)
#define re                 return
#define p_q                priority_queue
#define FAST               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
//find_by_order(k)  --> value at kth index (iterator)
//order_of_key(k)   --> index of value k

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const int mod = 1000000007;
const int modc = 998244353;
const int inf = LLONG_MAX;
const int neg_inf = LLONG_MIN;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use rng() instead of rand() //shuffle(all(a),rng)

int inline power(int a, int b, int p){
    a %= p;
    int ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

int mod_inv(int n, int p){
    return power(n,p-2, p);
}

bool inline isPrime(int n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(17) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
int ston(string s)
{
	int a = 0;
	reverse(s.begin(),s.end());
	int pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	if(si(binaryNum) == 0)
		binaryNum.pb('0');
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
int bton(string &s, int base)
{
	int ans = 0;
	int pow  = 1;
	rev(all(s));
	for(auto x : s)
	{
		if(x >= 'a' && x <= 'z')
			ans += (x - 'a' + 10)*pow;
		else
			ans += (x-'0')*pow;
		pow *= base;
	}
	return ans;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<si(v);i++)
		cin >> v[i];
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const int M = 5e5;
/*
int fact[M];
int ncr(int n, int r)
{
	int ans = fact[n];
	int denom = (fact[r]*fact[n-r])%mod;
	ans = (ans * mod_inv(denom,mod))%mod;
	return ans;
}
*/
//vector<int>v[M];

void solve()
{
	int i,j,sum = 0,prod = 1,maxl = neg_inf, minl = inf;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int one_s = 0 , one_t = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			one_s++;
		if(t[i] == '1')
			one_t++;
	}
	if(one_s != one_t)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	set<int>one,zero;
	for(i=0;i<si(diff);i++)
		if(diff[i] == '1')
			one.insert(i);
		else
			zero.insert(i);
	int ans = 0;
	while(1)
	{
		if(si(zero) == 0 || si(one) == 0)
		{
			ans += si(zero) + si(one);
			break;
		}
		int end = -1;
		int last = -1;
		int first_zero = *zero.begin();
		int first_one = *one.begin();
		if(first_zero < first_one)
		{
			end = 0;
			last = first_zero;
			zero.erase(zero.begin());
		}
		else
		{
			end = 1;
			last = first_one;
			one.erase(one.begin());
		}
		while(1)
		{
			if(end == 0)
			{
				auto it = one.lb(last);
				if(it == one.end())
					break;
				last = *it;
				end = 1;
				one.erase(it);
			}
			else
			{
				auto it = zero.lb(last);
				if(it == zero.end())
					break;
				last = *it;
				end = 0;
				zero.erase(it);
			}
		}
		dbg(end,last);
		ans++;
	}
	cout << ans << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	/*
	fact[0] = 1;
	for(int i = 1;i<M;i++)
		fact[i] = (i * fact[i-1])%mod;
		*/
	int test = 1;
	while(t--)
	{
		//cout << "Case #" << test << ": ";
		solve();
		test++;
	}
}


//author ----> noobiesAG

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int                long long
#define double             long double
#define pb                 push_back
#define mp                 make_pair
#define ld                 long double
#define vi                 vector<int>
#define vvi                vector<vector<int>>
#define vpii               vector<pair<int,int>>
#define pii                pair<int,int>
#define mii                map<int,int>
#define umap               unordered_map
#define all(c)             c.begin(),c.end()
#define si(c)              (int)c.size()
#define lb                 lower_bound
#define ub                 upper_bound
#define gi                 greater<int>
#define rev                reverse
#define ff                 first
#define ss                 second
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define ayes               cout << "Yes" << endl
#define ano                cout << "No" << endl
#define nl                 cout << endl
#define hello              cerr << "hello" << endl
#define sp(x)              fixed << setprecision(x)
#define re                 return
#define p_q                priority_queue
#define FAST               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_multiset;
//find_by_order(k)  --> value at kth index (iterator)
//order_of_key(k)   --> index of value k

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const int mod = 1000000007;
const int modc = 998244353;
const int inf = LLONG_MAX;
const int neg_inf = LLONG_MIN;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use rng() instead of rand() //shuffle(all(a),rng)

int inline power(int a, int b, int p){
    a %= p;
    int ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

int mod_inv(int n, int p){
    return power(n,p-2, p);
}

bool inline isPrime(int n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(17) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
int ston(string s)
{
	int a = 0;
	reverse(s.begin(),s.end());
	int pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	if(si(binaryNum) == 0)
		binaryNum.pb('0');
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
int bton(string &s, int base)
{
	int ans = 0;
	int pow  = 1;
	rev(all(s));
	for(auto x : s)
	{
		if(x >= 'a' && x <= 'z')
			ans += (x - 'a' + 10)*pow;
		else
			ans += (x-'0')*pow;
		pow *= base;
	}
	return ans;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<si(v);i++)
		cin >> v[i];
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const int M = 5e5;
/*
int fact[M];
int ncr(int n, int r)
{
	int ans = fact[n];
	int denom = (fact[r]*fact[n-r])%mod;
	ans = (ans * mod_inv(denom,mod))%mod;
	return ans;
}
*/
//vector<int>v[M];

void solve()
{
	int i,j,sum = 0,prod = 1,maxl = neg_inf, minl = inf;
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	if(s == t)
	{
		W(0);
		re;
	}
	int one_s = 0 , one_t = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
			one_s++;
		if(t[i] == '1')
			one_t++;
	}
	if(one_s != one_t)
	{
		W(-1);
		re;
	}
	string diff;
	for(i=0;i<n;i++)
		if(s[i] != t[i])
			diff.pb(s[i]);
	set<int>one,zero;
	for(i=0;i<si(diff);i++)
		if(diff[i] == '1')
			one.insert(i);
		else
			zero.insert(i);
	int ans = 0;
	while(1)
	{
		if(si(zero) == 0 || si(one) == 0)
		{
			ans += si(zero) + si(one);
			break;
		}
		int end = -1;
		int last = -1;
		int first_zero = *zero.begin();
		int first_one = *one.begin();
		if(first_zero < first_one)
		{
			end = 0;
			last = first_zero;
			zero.erase(zero.begin());
		}
		else
		{
			end = 1;
			last = first_one;
			one.erase(one.begin());
		}
		while(1)
		{
			if(end == 0)
			{
				auto it = one.lb(last);
				if(it == one.end())
					break;
				last = *it;
				end = 1;
				one.erase(it);
			}
			else
			{
				auto it = zero.lb(last);
				if(it == zero.end())
					break;
				last = *it;
				end = 0;
				zero.erase(it);
			}
		}
		ans++;
	}
	cerr << "Hello  ayush" << '\n';
	cout << ans << endl;
}
int32_t main()
{
	FAST;
	int t = 1;
	/*
	fact[0] = 1;
	for(int i = 1;i<M;i++)
		fact[i] = (i * fact[i-1])%mod;
		*/
	int test = 1;
	while(t--)
	{
		//cout << "Case #" << test << ": ";
		solve();
		test++;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
   //cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      int cnt=0;
      str+='1';
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1]&&str[i]=='1')
            cnt++;
      }
      if(str.length()>2*cnt)
        cnt++;
      cout<<cnt<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
   //cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      int cnt=1,ans=0;
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1])
         {
                cnt++;
                ans = max(cnt,ans);

         }
         else cnt = 1;
      }
      ans = max(ans,cnt);
      cout<<ans<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
   //cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      int cnt=0;
      for(int i=0;i<str.length()-1;i++)
      {
          if(str[i]==str[i+1]&&str[i]=='1')
            cnt++;
      }
      if(str.length()>2*cnt)
        cnt++;
      cout<<cnt<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
   //cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      int cnt=1,ans=0;
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1])
         {
                cnt++;
                ans = max(cnt,ans);

         }
         else cnt = 1;
      }
      cout<<ans<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
   cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      int cnt=1,ans=0;
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1])
         {
                cnt++;
                ans = max(cnt,ans);

         }
         else cnt = 1;
      }
      ans = max(cnt,ans);
      cout<<ans<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
  // cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      int cnt=0;
      if(str.length())
      str+='1';
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1]&&str[i]=='1')
            cnt++;
      }
      if(str.length()>2*cnt)
        cnt++;
      cout<<cnt<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
  // cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      if(str.length()==0)
        return cout<<0 , 0;
      int cnt=1,ans=0;
      str+='1';
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1]&&str[i]=='1')
         {
                cnt++;
                ans = max(cnt,ans);

         }
         else cnt = 1;
      }
      ans = max(ans,cnt);
      cout<<ans<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

int maxsum_subarray(vector<int>v)
{
    int sum=0,ans=0,best=0;
    for(auto &it : v)
    {
        sum += it;
        if(sum<=0)
            sum = 0;
        ans = max(ans,sum);
    }
    return ans;
}
signed main()
{
    fast;
   int test = 1;
   //cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      vector<int>v1,v2;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(s[i]=='0')
            {
                v1.push_back(1);
                v2.push_back(-1);
            }
            else
            {
                v1.push_back(-1);
                v2.push_back(1);
            }

      }
      int ans = max(maxsum_subarray(v1),maxsum_subarray(v2));
      cout<<ans<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);

signed main()
{
    fast;
   int test = 1;
//   cin>>test;
   while(test-->0)
   {
      int n;
      cin>>n;
      string s,t;
      cin>>s>>t;
      int zero_in_s = 0 , zero_in_t = 0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='0')
            zero_in_s++;
          if(t[i]=='0')
            zero_in_t++;
      }
      if(zero_in_s!=zero_in_t)
      {
          cout<<"-1";
          continue;
      }
      char ch;
      string str;
      int firstdifferent = 0;
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]==t[i])
            continue;
          if(firstdifferent)
          {
              if(s[i]==ch)
                str+='1';
              else str+='2';
          }
          else{
            firstdifferent = 1;
            ch = s[i];
            str+='1';
          }
      }
      if(str.length()==0)
      return cout<<0 , 0;
      int cnt=1,ans=0;
      for(int i=0;i<str.length();i++)
      {
          if(str[i]==str[i+1])
         {
                cnt++;
                ans = max(cnt,ans);

         }
         else cnt = 1;
      }
      ans = max(ans,cnt);
      cout<<ans<<'\n';

   }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+5;
const int INF = 0x3f3f3f3f;
int n,mx=-1,mn=INF,sum=0;
char s1[MAX],s2[MAX];
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		sum+=s1[i]-'0';
		sum-=s2[i]-'0';
		mx=max(mx,sum);
		mn=min(mn,sum);
	}
	if(sum!=0){
		printf("-1\n");
	}
	else{
		printf("%d\n",mx-mn);
	}
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2;
char s1[MAX],s2[MAX];
vector<int> list1,list2,lisan,list3,list4;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.push_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.push_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	for(auto c:list1){
		lisan.push_back(c);
	}
	for(auto c:list2){
		lisan.push_back(c);
	}
	sort(lisan.begin(),lisan.end());
	for(auto c:list1){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		list3.push_back(index);
	}
	for(auto c:list2){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		list4.push_back(index);
	}
	int len1 = list3.size(),ans1=0;
	for(int i=1;i<len1;++i){
		if(list3[i]==list3[i-1]+1){
			++ans1;
		}
	}
	++ans1;
	int len2 = list4.size(),ans2=0;
	for(int i=1;i<len2;++i){
		if(list4[i]==list4[i-1]+1){
			++ans2;
		}
	}
	++ans2;
	printf("%d\n",max(ans1,ans2));
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,mx=-1,mn=INF,sum=0;
char s1[MAX],s2[MAX];
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		sum+=s1[i]-'0';
		sum-=s2[i]-'0';
		mx=max(mx,sum);
		mn=min(mn,sum);
	}
	if(sum!=0){
		printf("-1\n");
	}
	else{
		printf("%d\n",mx-mn);
	}
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2;
char s1[MAX],s2[MAX];
vector<int> list1,list2,lisan,list3,list4;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==num2&&num1==0){
		printf("0\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.push_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.push_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==0){
		printf("0\n");
		return;
	}
	for(auto c:list1){
		lisan.push_back(c);
	}
	for(auto c:list2){
		lisan.push_back(c);
	}
	sort(lisan.begin(),lisan.end());
	for(auto c:list1){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		list3.push_back(index);
	}
	for(auto c:list2){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		list4.push_back(index);
	}
//	for(auto c:list3){
//		cout<<c<<" ";
//	}
//	cout<<endl;
//	for(auto c:list4){
//		cout<<c<<" ";
//	}
//	cout<<endl;
	int len1 = list3.size(),ans1=0;
	for(int i=1;i<len1;++i){
		if(list3[i]==list3[i-1]+1){
			++ans1;
		}
	}
	++ans1;
	int len2 = list4.size(),ans2=0;
	for(int i=1;i<len2;++i){
		if(list4[i]==list4[i-1]+1){
			++ans2;
		}
	}
	++ans2;
	printf("%d\n",max(ans1,ans2));
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2,er[MAX];
char s1[MAX],s2[MAX];
bool vis[MAX];
vector<int> list1,list2,lisan,list3,list4;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==num2&&num1==0){
		printf("0\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.push_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.push_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==0){
		printf("0\n");
		return;
	}
	for(auto c:list1){
		lisan.push_back(c);
	}
	for(auto c:list2){
		lisan.push_back(c);
	}
	sort(lisan.begin(),lisan.end());
	for(auto c:list1){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=0;
		list3.push_back(index);
	}
	for(auto c:list2){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=1;
		list4.push_back(index);
	}
//	for(auto c:list3){
//		cout<<c<<" ";
//	}
//	cout<<endl;
//	for(auto c:list4){
//		cout<<c<<" ";
//	}
//	cout<<endl;
	int len = list1.size()+list2.size(),ans=0;
//	printf("len = %d\n",len);
	for(int i=1;i<=len;++i){
		if(vis[i]) continue;
//		printf("i = %d\n",i);
		++ans;
		int now = i;
//		printf("i = %d,er[i] = %d\n",i,er[i]);
		while(now<=len){
			vis[now]=true;
			if(er[now]==0){
				if(lower_bound(list4.begin(),list4.end(),now)==list4.end()) break;
				int nxt = lower_bound(list4.begin(),list4.end(),now)-list4.begin();
				nxt=list4[nxt];
				now=nxt;
				list4.erase(lower_bound(list4.begin(),list4.end(),now));
			}
			else{
				if(lower_bound(list3.begin(),list3.end(),now)==list3.end()) break;
				int nxt = lower_bound(list3.begin(),list3.end(),now)-list3.begin();
				nxt=list3[nxt];
//				printf("i = %d,nxt = %d\n",i,nxt);
				now=nxt;
				list3.erase(lower_bound(list3.begin(),list3.end(),now));
			}
		}
//		if(i==1){
//			printf("len = %d,ans = %d\n",len,ans);
//			for(int i=1;i<=len;++i){
//				printf("%d ",vis[i]);
//			}
//			printf("\n");
//		}
	}
	printf("%d\n",ans);
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2,er[MAX];
char s1[MAX],s2[MAX];
bool vis[MAX];
vector<int> list1,list2,lisan,list3,list4;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==num2&&num1==0){
		printf("0\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.emplace_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.emplace_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==0){
		printf("0\n");
		return;
	}
	for(auto c:list1){
		lisan.emplace_back(c);
	}
	for(auto c:list2){
		lisan.emplace_back(c);
	}
	sort(lisan.begin(),lisan.end());
	for(auto c:list1){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=0;
		list3.emplace_back(index);
	}
	for(auto c:list2){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=1;
		list4.emplace_back(index);
	}
//	for(auto c:list3){
//		cout<<c<<" ";
//	}
//	cout<<endl;
//	for(auto c:list4){
//		cout<<c<<" ";
//	}
//	cout<<endl;
	int len = list1.size()+list2.size(),ans=0;
//	printf("len = %d\n",len);
	for(int i=1;i<=len;++i){
		if(vis[i]) continue;
//		printf("i = %d\n",i);
		++ans;
		int now = i;
//		printf("i = %d,er[i] = %d\n",i,er[i]);
		while(now<=len){
			vis[now]=true;
			if(er[now]==0){
				if(lower_bound(list4.begin(),list4.end(),now)==list4.end()) break;
				int nxt = lower_bound(list4.begin(),list4.end(),now)-list4.begin();
				nxt=list4[nxt];
				now=nxt;
				list4.erase(lower_bound(list4.begin(),list4.end(),now));
			}
			else{
				if(lower_bound(list3.begin(),list3.end(),now)==list3.end()) break;
				int nxt = lower_bound(list3.begin(),list3.end(),now)-list3.begin();
				nxt=list3[nxt];
//				printf("i = %d,nxt = %d\n",i,nxt);
				now=nxt;
				list3.erase(lower_bound(list3.begin(),list3.end(),now));
			}
		}
//		if(i==1){
//			printf("len = %d,ans = %d\n",len,ans);
//			for(int i=1;i<=len;++i){
//				printf("%d ",vis[i]);
//			}
//			printf("\n");
//		}
	}
	printf("%d\n",ans);
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2;
char s1[MAX],s2[MAX];
vector<int> list1,list2;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.push_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.push_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	int len = list1.size(),ans=0;
	for(int i=1;i<len;++i){
		if(list1[i]==list1[i-1]+1){
			++ans;
		}
	}
	++ans;
	printf("%d\n",ans);
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2,er[MAX];
char s1[MAX],s2[MAX];
bool vis[MAX];
vector<int> list1,list2,lisan;
set<int> list3,list4;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==num2&&num1==0){
		printf("0\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.push_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.push_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==0){
		printf("0\n");
		return;
	}
	for(auto c:list1){
		lisan.push_back(c);
	}
	for(auto c:list2){
		lisan.push_back(c);
	}
	sort(lisan.begin(),lisan.end());
	for(auto c:list1){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=0;
		list3.insert(index);
	}
	for(auto c:list2){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=1;
		list4.insert(index);
	}
//	for(auto c:list3){
//		cout<<c<<" ";
//	}
//	cout<<endl;
//	for(auto c:list4){
//		cout<<c<<" ";
//	}
//	cout<<endl;
	int len = list1.size()+list2.size(),ans=0;
//	printf("len = %d\n",len);
	for(int i=1;i<=len;++i){
		if(vis[i]) continue;
//		printf("i = %d\n",i);
		++ans;
		int now = i;
//		printf("i = %d,er[i] = %d\n",i,er[i]);
		while(now<=len){
			vis[now]=true;
			if(er[now]==0){
				if(lower_bound(list4.begin(),list4.end(),now)==list4.end()) break;
				auto nxt = lower_bound(list4.begin(),list4.end(),now);
				now=(*nxt);
				list4.erase(now);
			}
			else{
				if(lower_bound(list3.begin(),list3.end(),now)==list3.end()) break;
				auto nxt = lower_bound(list3.begin(),list3.end(),now);
				now=(*nxt);
				list3.erase(now);
			}
		}
//		if(i==1){
//			printf("len = %d,ans = %d\n",len,ans);
//			for(int i=1;i<=len;++i){
//				printf("%d ",vis[i]);
//			}
//			printf("\n");
//		}
	}
	printf("%d\n",ans);
}
int main(void)
{
	solve();
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6+5;
const int INF = 0x3f3f3f3f;
int n,num1,num2,er[MAX];
char s1[MAX],s2[MAX];
bool vis[MAX];
vector<int> list1,list2,lisan;
unordered_set<int> list3,list4;
void solve(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;++i){
		if(s1[i]=='0') ++num1;
		if(s2[i]=='0') ++num2;
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==num2&&num1==0){
		printf("0\n");
		return;
	}
	num1=num2=0;
	for(int i=1;i<=n;++i){
		if(s1[i]=='0'&&s2[i]=='1'){
			++num1;
			list1.emplace_back(i);
		}
		if(s1[i]=='1'&&s2[i]=='0'){
			++num2;
			list2.emplace_back(i);
		}
	}
	if(num1!=num2){
		printf("-1\n");
		return;
	}
	if(num1==0){
		printf("0\n");
		return;
	}
	for(auto c:list1){
		lisan.emplace_back(c);
	}
	for(auto c:list2){
		lisan.emplace_back(c);
	}
	sort(lisan.begin(),lisan.end());
	for(auto c:list1){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=0;
		list3.insert(index);
	}
	for(auto c:list2){
		int index = lower_bound(lisan.begin(),lisan.end(),c)-lisan.begin();
		++index;
		er[index]=1;
		list4.insert(index);
	}
//	for(auto c:list3){
//		cout<<c<<" ";
//	}
//	cout<<endl;
//	for(auto c:list4){
//		cout<<c<<" ";
//	}
//	cout<<endl;
	int len = list1.size()+list2.size(),ans=0;
//	printf("len = %d\n",len);
	for(int i=1;i<=len;++i){
		if(vis[i]) continue;
//		printf("i = %d\n",i);
		++ans;
		int now = i;
//		printf("i = %d,er[i] = %d\n",i,er[i]);
		while(now<=len){
			vis[now]=true;
			if(er[now]==0){
				if(lower_bound(list4.begin(),list4.end(),now)==list4.end()) break;
				auto nxt = lower_bound(list4.begin(),list4.end(),now);
				now=(*nxt);
				list4.erase(now);
			}
			else{
				if(lower_bound(list3.begin(),list3.end(),now)==list3.end()) break;
				auto nxt = lower_bound(list3.begin(),list3.end(),now);
				now=(*nxt);
				list3.erase(now);
			}
		}
//		if(i==1){
//			printf("len = %d,ans = %d\n",len,ans);
//			for(int i=1;i<=len;++i){
//				printf("%d ",vis[i]);
//			}
//			printf("\n");
//		}
	}
	printf("%d\n",ans);
}
int main(void)
{
	solve();
	return 0;
 }


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}

        vector<char>ans;
        for(int i=0;i<n;i++)
        {
            if(s[i]!=t[i])ans.push_back(s[i]);
        }
        int mx1=0,mx2=0;
        int i=0;
        while(i<ans.size())
        {
            if(ans[i]=='1')
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx1=max(mx1,cnt1);
            }
            else
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx2=max(mx2,cnt1);
            }
        }
         cout<<mx1+mx2<<endl;

    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}
        int mx1=0;
        int mx2=0;
        int i=0;
        //int cnt=0;
        while(i<n)
        {
           if(s[i]=='1'&&t[i]=='0')
           {
               int cnt=0;
                   while(i<n&&(s[i]=='1'&&t[i]=='0'||s[i]==t[i]))
                   {
                       if(s[i]==t[i]){i++;continue;}
                       cnt++;
                       i++;
                   }
                   mx1=max(mx1,cnt);
                  while(1)
                  {
                      if(s[i]==t[i]){i++;continue;}
                      if(s[i]=='0'&&t[i]=='1'){cnt--;i++;}
                      else {cnt++;i++;}
                      if(cnt==0)break;
                  }
           }
           else if(s[i]=='0'&&t[i]=='1')
           {
               int cnt=0;
                   while(i<n&&(s[i]=='0'&&t[i]=='1'||s[i]==t[i]))
                   {
                       if(s[i]==t[i]){i++;continue;}
                       cnt++;
                       i++;
                   }
                   mx2=max(mx2,cnt);
                  while(1)
                  {
                      if(s[i]==t[i]){i++;continue;}
                      if(s[i]=='1'&&t[i]=='0'){cnt--;i++;}
                      else {cnt++;i++;}
                      if(cnt==0)break;
                  }
           }
           else i++;

        }
        cout<<mx1+mx2<<endl;
    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}
        int mx=0;
        int i=0;
        while(i<n)
        {
            int cnt=0;
            if(s[i]=='1'&&t[i]=='0'){
            while(s[i]=='1'&&t[i]=='0')
            {
                cnt++;
                i++;
            }
            mx=max(mx,cnt);
            }
            else i++;
        }
        cout<<mx<<endl;
    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}
        int mx1=0;
        int mx2=0;
        int i=0;
        //int cnt=0;
        while(i<n)
        {
           if(s[i]=='1'&&t[i]=='0')
           {
               int cnt=0;
                   while(i<n&&(s[i]=='1'&&t[i]=='0'||s[i]==t[i]))
                   {
                       if(s[i]==t[i]){i++;continue;}
                       cnt++;
                       i++;
                   }
                   mx1=max(mx1,cnt);
                  while(1)
                  {
                      if(s[i]==t[i]){i++;continue;}
                      if(s[i]=='0'&&t[i]=='1'){cnt--;i++;}
                      if(cnt==0)break;
                  }
           }
           else if(s[i]=='0'&&t[i]=='1')
           {
               int cnt=0;
                   while(i<n&&(s[i]=='0'&&t[i]=='1'||s[i]==t[i]))
                   {
                       if(s[i]==t[i]){i++;continue;}
                       cnt++;
                       i++;
                   }
                   mx2=max(mx2,cnt);
                  while(1)
                  {
                      if(s[i]==t[i]){i++;continue;}
                      if(s[i]=='1'&&t[i]=='0'){cnt--;i++;}
                      if(cnt==0)break;
                  }
           }
           else i++;

        }
        cout<<mx1+mx2<<endl;
    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}
        int mx1=0;
        int mx2=0;
        int i=0;
        //int cnt=0;
        while(i<n)
        {
           if(s[i]=='1'&&t[i]=='0')
           {
               int cnt=0;
                   while(i<n&&(s[i]=='1'&&t[i]=='0'||s[i]==t[i]))
                   {
                       if(s[i]==t[i]){i++;continue;}
                       cnt++;
                       i++;
                   }
                   mx1=max(mx1,cnt);
                  while(1)
                  {
                      if(s[i]==t[i]){i++;continue;}
                      if(s[i]=='0'&&t[i]=='1'){cnt--;i++;}
                      else {cnt++;mx1=max(mx1,cnt);i++;}
                      if(cnt==0)break;
                  }
           }
           else if(s[i]=='0'&&t[i]=='1')
           {
               int cnt=0;
                   while(i<n&&(s[i]=='0'&&t[i]=='1'||s[i]==t[i]))
                   {
                       if(s[i]==t[i]){i++;continue;}
                       cnt++;
                       i++;
                   }
                   mx2=max(mx2,cnt);
                  while(1)
                  {
                      if(s[i]==t[i]){i++;continue;}
                      if(s[i]=='1'&&t[i]=='0'){cnt--;i++;}
                      else {cnt++;mx2=max(mx2,cnt);i++;}
                      if(cnt==0)break;
                  }
           }
           else i++;

        }
        cout<<mx1+mx2<<endl;
    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}

        vector<char>ans;
        for(int i=0;i<n;i++)
        {
            if(s[i]!=t[i])ans.push_back(s[i]);
        }
        int mx1=0,mx2=0;
        int i=0;
        while(i<ans.size())
        {
            if(ans[i]=='1')
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx1=max(mx1,cnt1);
            }
            else
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx2=max(mx2,cnt2);
            }
        }
         cout<<mx1+mx2<<endl;

    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}
        int mx=0;
        int i=0;
        while(i<n)
        {
            int cnt=0;
            if(s[i]=='1'&&t[i]=='0'){
            while((i<n)&&((s[i]=='1'&&t[i]=='0')||s[i]==t[i]))
            {
                if(s[i]==t[i]){i++;continue;}
                cnt++;
                i++;
            }
            mx=max(mx,cnt);
            }
            else i++;
        }
        cout<<mx<<endl;
    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt0=0;int cnt1=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt0++;
            else cnt1++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt0--;
            else cnt1--;
        }
        if(cnt1!=0||cnt0!=0){cout<<-1<<endl;return 0;}

        vector<char>ans;
        for(int i=0;i<n;i++)
        {
            if(s[i]!=t[i])ans.push_back(s[i]);
        }
        int mx1=0,mx2=0;
        int i=0;
        while(i<ans.size())
        {
            if(ans[i]=='1')
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx1=max(mx1,cnt1);
            }
            else
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx2=max(mx2,cnt0);
            }
        }
         cout<<mx1+mx2<<endl;

    }

}


#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAXN = 5000001;
const int mod=998244353;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s,t;
        cin>>s>>t;
        int cnt00=0;int cnt11=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='0')cnt00++;
            else cnt11++;
        }
        for(int i=0;i<n;i++)
        {
            if(t[i]=='0')cnt00--;
            else cnt11--;
        }
        if(cnt11!=0||cnt00!=0){cout<<-1<<endl;return 0;}

        vector<char>ans;
        for(int i=0;i<n;i++)
        {
            if(s[i]!=t[i])ans.push_back(s[i]);
        }
        int mx1=0,mx2=0;
        int i=0;
        while(i<ans.size())
        {
            if(ans[i]=='1')
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx1=max(mx1,cnt1);
            }
            else
            {
                int cnt1=0;
                int cnt0=0;
               while(1)
               {
                  if(ans[i]=='1')cnt1++;
                  if(ans[i]=='0')cnt0++;
                  i++;
                   if(cnt1==cnt0)break;
               }
               mx2=max(mx2,cnt0);
            }
        }
         cout<<mx1+mx2<<endl;

    }

}