#include <bits/stdc++.h>

using namespace std;

int sol(string s, string t){
    int res = 0;
    int q = 0;
    for (int i = 0; i < s.size(); ++ i){
        if (s[i] == '0'){
            if (t[i] == '0'){
                if (q != 0){
                    res += 1;
                }
            }
            else{
                q += 1;
            }
        }
        else{
            if (t[i] == '0'){
                q -= 1;
                res += 1;
            }
        }
    }
    return res + q;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
    int n; cin >> n;
    string s, t; cin >> s >> t;
    vector <int> cntt(2), cnts(2);
    for (char c : s) cnts[c - '0'] += 1;
    for (char c : t) cntt[c - '0'] += 1;
    int ans = sol(s, t);
    /*for (char &c : s) c = char(((c - '0') ^ 1) + '0');
    for (char &c : t) c = char(((c - '0') ^ 1) + '0');
    ans = min(ans, sol(s, t));*/
    if (cntt[0] != cnts[0] || cntt[1] != cnts[1]) return cout << -1, 0;
    cout << ans;
}

//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>

#include<stdio.h>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

int get_gcd(int n, int m) {
	if (n < m) swap(n, m);
	while (m) {
		swap(n, m);
		m %= n;
	}
	return n;
}

int get_lcm(int n, int m) {
	return n / get_gcd(n, m)*m;
}

struct BIT //0-indexed
{
	vector<int> node;
	int mn;

	BIT(int mn)
	{
		this->mn = mn;
		node.resize(mn + 1, 0);
	}

	void add(int i, int x)
	{
		i++;
		while (i <= mn)
		{
			node[i] += x;
			i += (i&-i);
		}
	}

	int sum(int i)
	{
		i++;
		int res = 0;
		while (i > 0)
		{
			res += node[i];
			i -= (i&-i);
		}
		return res;
	}

	//k:0-indexed
	int get(long long k) {
		++k;
		int res = 0;
		int N = 1; while (N < (int)node.size()) N *= 2;

		for (int i = N / 2; i > 0; i /= 2) {
			if (res + i < (int)node.size() && node[res + i] < k) {
				k = k - node[res + i];
				res = res + i;
			}
		}
		return res;
	}
};

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int H, W, M;
	cin >> H >> W >> M;

	int ans = H * W;
	vector<int> R(H, W), C(W, H);
	int X, Y;
	vector<pii> P(M);
	rep(i, 0, M)
	{
		cin >> Y >> X;
		Y--, X--;
		chmin(R[Y], X);
		chmin(C[X], Y);
		P[i] = mp(X, Y);
	}

	sort(all(P));
	vector<bool> USED(H, false);
	int pi = 0;

	BIT bit(H + 3);
	
	int mi = INF;
	rep(i, 0, W)
	{
		while (pi < M&&P[pi].first <= i)
		{
			if (!USED[P[pi].second])
			{
				USED[P[pi].second] = true;
				bit.add(P[pi].second, 1);
			}
			pi++;
		}
		chmin(mi, C[i]);
		
		int ma = max(C[0], mi == 0 ? 0 : C[i]);
		int res = H - ma;
		res += bit.sum(ma - 1);
		if (mi != 0 && C[i] > 0)res -= bit.sum(C[i] - 1);
		ans -= res;
	}

	/*int mi = W;
	rep(i, 0, H)
	{
		chmin(mi, R[i]);
		if (mi == 0)break;
		ans += R[i];
	}
	mi = H;
	rep(i, 0, W)
	{
		chmin(mi, C[i]);
		if (mi == 0)break;
		ans += C[i];
	}

	mi = W;
	rep(i, 0, H)
	{
		chmin(mi, R[i]);
		ans -= mi;
	}*/

	cout << ans << endl;
	
	return 0;
}