#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(12), cin.tie(0), cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define sz(X) (int)((X).size())
#define what(x) cerr << #x << " is " << x << endl;

ostream &operator<<(ostream &out, string str) {
   for (char c : str)
      out << c;
   return out;
}
template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; }
template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
   out << '{';
   for (auto it = a.begin(); it != a.end(); it = next(it))
      out << (it != a.begin() ? ", " : "") << *it;
   return out << '}';
}
void dump() { cerr << "\n"; }
template <class T, class... Ts> void dump(T a, Ts... x) {
   cerr << a << ", ";
   dump(x...);
}
#define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)

int n;
string S, T;

int32_t main() {
   _upgrade;
   cin >> n >> S >> T;
   //    reverse(all(S));
   //    reverse(all(T));
   long long cnt = 0;
   queue<int> plus;

   rep(i, n) {
      if (S[i] == '0' && T[i] == '1') {
         plus.push(i);
      }
      if (S[i] == '1' && T[i] == '0') {
         if (!plus.empty()) {
            int a = plus.front();
            plus.pop();
            cnt += (i - a);
         } else
            plus.push(i);
      }
   }
   if (!plus.empty()) {
      cout << -1 << endl;
      return 0;
   }
   cout << cnt << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  int h,w,ans=0;
  vector<string> s(11);
  cin>>h>>w;
  REP(i,h) cin>>s.at(i);
  REP(i,h) REP(j,w){
    if(s.at(i).at(j)=='#'){
      int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
      bool f[4]={0,0,0,0};
      REP(k,4){
        if(s.at(i+dy[k]).at(j+dx[k])=='.'){
          ans++;
          f[k]=1;
        }
      }
      if(s.at(i).at(j+1)=='#') REP(k,4){
        if(s.at(i+dy[k]).at(j+1+dx[k])=='.'&&f[k]) ans--;
      }
      if(s.at(i+1).at(j)=='#') REP(k,4){
        if(s.at(i+1+dy[k]).at(j+dx[k])=='.'&&f[k]) ans--;
      }
    }
  }
  cout<<ans<<endl;
}
