#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <cassert>
#include <stack>

#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/chmin_chmax.cpp"

template <class T, class U>
constexpr bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
constexpr bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

/**
 * @title Chmin/Chmax
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

#line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

class range {
  struct iter {
    std::size_t itr;
    constexpr iter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { ++itr; }
    constexpr bool operator != (iter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  struct reviter {
    std::size_t itr;
    constexpr reviter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { --itr; }
    constexpr bool operator != (reviter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  const iter first, last;

public:
  constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { }
  constexpr iter begin() const noexcept { return first; }
  constexpr iter end() const noexcept { return last; }
  constexpr reviter rbegin() const noexcept { return reviter(*last - 1); } 
  constexpr reviter rend() const noexcept { return reviter(*first - 1); } 
};

/**
 * @title Range
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/rev.cpp"

#include <type_traits>
#include <iterator>
#line 6 "/Users/kodamankod/Desktop/cpp_programming/Library/other/rev.cpp"

template <class T>
class rev_impl {
public:
  using iterator = decltype(std::rbegin(std::declval<T>()));

private:
  const iterator M_begin;
  const iterator M_end;

public:
  constexpr rev_impl(T &&cont) noexcept: M_begin(std::rbegin(cont)), M_end(std::rend(cont)) { }
  constexpr iterator begin() const noexcept { return M_begin; }
  constexpr iterator end() const noexcept { return M_end; }
};

template <class T>
constexpr decltype(auto) rev(T &&cont) {
  return rev_impl<T>(std::forward<T>(cont));
}

/**
 * @title Reverser
 */
#line 18 "main.cpp"

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  usize N;
  std::cin >> N;
  std::vector<u32> S(N), T(N);
  for (auto &x: S) {
    char c;
    std::cin >> c;
    x = c - '0';
  }
  for (auto &x: T) {
    char c;
    std::cin >> c;
    x = c - '0';
  }
  std::stack<usize> one;
  {
    u32 count = 0;
    for (auto i: rev(range(0, N))) {
      if (S[i] == 1) {
        count += 1;
        one.push(i);
      }
      if (T[i] == 1) {
        if (count == 0) {
          std::cout << "-1\n";
          return 0;
        }
        count -= 1;
      }
    }
    if (count % 2 == 1) {
      std::cout << "-1\n";
      return 0;
    }
  }
  u64 ans = 0;
  for (auto i: range(0, N)) {
    if (T[i] == 1) {
      while (one.top() < i) {
        usize x = one.top();
        one.pop();
        usize y = one.top();
        one.pop();
        ans += y - x;
      }
      ans += one.top() - i;
      one.pop();
    }
  }      
  while (!one.empty()) {
    usize x = one.top();
    one.pop();
    usize y = one.top();
    one.pop();
    ans += y - x;
  }
  std::cout << ans << '\n';
  return 0;
}

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

int n;
string s, t;
set<int> have;

int nxt(int idx)
{
	auto it = have.upper_bound(idx);
	if(it == have.end()){
		cout<<-1<<'\n';
		exit(0);
	}
	int res = *it;
	have.erase(it);
	s[res] = '0';
	return res;
}

void solve()
{
	int a = 0, b = 0;
	for(int i=0;i<n;++i){
		a+=(s[i]=='1');
		b+=(t[i]=='1');
	}
	if(a%2!=b%2 || a<b){
		cout<<-1<<'\n';
		return;
	}
	for(int i=0;i<n;++i)if(s[i]=='1')have.insert(i);
	ll ans = 0;
	for(int i=0;i<n;++i){
		if(s[i]!=t[i]){
			if(s[i]=='1'){
				ans+=1+(nxt(i)-(i+1));
			}else{
				ans += (nxt(i)-i);
			}
		}
	}
	cout<<ans<<'\n';
}

int main()
{
	cin >> n >> s >> t;
	solve();
	return 0;
}
