#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
char ch[maxn];
int Min[maxn];
int main() {
  int n;
  cin >> n;
  scanf("%s", ch + 1);
  int sum = n;
  memset(Min, inf, sizeof(Min));
  Min[sum] = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ch[i] == '0')
      sum--;
    else
      sum++;
    Min[sum] = min(Min[sum], i);
    ans = max(ans, i - Min[sum]);
  }
  cout << ans << endl;
  return 0;
}
