#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod = (int)1e9 + 7;
const long long INF = 1000000000000000000LL;
const int WASTE = (int)2e5;
int power(int a, int b, int m = mod) {
  if (b == 0) return 1;
  if (b == 1) return a;
  int x = power(a, b / 2, m) % m;
  x = (x * x) % m;
  if (b % 2) return (x * a) % m;
  return x;
}
const int N = 1e5 + 5;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  string s;
  cin >> n >> s;
  map<int, int> m;
  int c1 = 0, c2 = 0, ans = 0;
  m[0] = -1;
  for (int x = 0; x < s.length(); x++) {
    if (s[x] == '1')
      c1++;
    else
      c2++;
    if (m.find(c1 - c2) != m.end())
      ans = max(ans, x - m[c1 - c2]);
    else
      m[c1 - c2] = x;
  }
  cout << ans;
  return 0;
}
