#include <bits/stdc++.h>

using namespace std;

const int N = 15;

char str[N][N];

int n, m, ans;

struct Res {
  int x, y;
};

bool cmp1(Res a, Res b) {
  return a.x != b.x ? a.x < b.x : a.y < b.y;
}

bool cmp2(Res a, Res b) {
  return a.y != b.y ? a.y < b.y : a.x < b.x;
}

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> str[i] + 1;
  }
  vector<Res> vt;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '#' && str[i - 1][j] == '.') {
        vt.push_back({i, j});
      }
    }
  }
  sort(vt.begin(), vt.end(), cmp1);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].x == vt[i - 1].x && vt[i].y == vt[i - 1].y + 1) {
      continue;
    }
    ans++;
  }
  ans++;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '#' && str[i + 1][j] == '.') {
        vt.push_back({i, j});
      }
    }
  }
  sort(vt.begin(), vt.end(), cmp1);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].x == vt[i - 1].x && vt[i].y == vt[i - 1].y + 1) {
      continue;
    }
    ans++;
  }
  ans++;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '#' && str[i][j + 1] == '.') {
        vt.push_back({i, j});
      }
    }
  }
  sort(vt.begin(), vt.end(), cmp2);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].y == vt[i - 1].y && vt[i].x == vt[i - 1].x + 1) {
      continue;
    }
    ans++;
  }
  ans++;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '#' && str[i][j - 1] == '.') {
        vt.push_back({i, j});
      }
    }
  }
  sort(vt.begin(), vt.end(), cmp2);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].y == vt[i - 1].y && vt[i].x == vt[i - 1].x + 1) {
      continue;
    }
    ans++;
  }
  ans++;
  cout << ans << "\n";
  return 0;
}
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, a;
  cin >> n;
  string s, t;
  vector<int> p, q;
  cin >> s >> t;
  for(int i = 0; i < n; i++){
    if(s[i] == '0')
      p.push_back(i);
    if(t[i] == '0')
      q.push_back(i);
  }
  a = 0;
  if(p.size() != q.size()){
    a = -1;
  }
  else{
    for(int i = 0; i < p.size(); i++){
      if(p[i] != q[i])
        a++;
    }
  }
  cout << a << endl;
}