#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-14;
const long long maxn = 100500;
const long long mod = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  map<long long, long long> cnt;
  long long ans = 0;
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ad = 0;
  cnt[0] = -1;
  for (long long i = 0; i < n; ++i) {
    if (s[i] == '0')
      ad--;
    else
      ad++;
    if (cnt.count(ad))
      ans = max(ans, i - cnt[ad]);
    else
      cnt[ad] = i;
  }
  cout << ans << '\n';
  return 0;
}
