#include <bits/stdc++.h>
using namespace std;
int vis[300000];
int main() {
  int n;
  char s[200000];
  while (~scanf("%d", &n)) {
    memset(vis, -1, sizeof(vis));
    int now = 100001;
    getchar();
    gets(s);
    int ans = 0;
    vis[now] = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i - 1] == '1')
        now++;
      else
        now--;
      if (vis[now] != -1)
        ans = max(ans, i - vis[now]);
      else
        vis[now] = i;
    }
    printf("%d\n", ans);
  }
  return 0;
}
