#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int m;
  int a[100003];
  int vis[200006];
  memset(a, 0, sizeof(a));
  memset(vis, 0, sizeof(vis));
  cin >> m;
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    char s;
    cin >> s;
    int num = s - '0';
    if (num == 1)
      a[i] = a[i - 1] + 1;
    else
      a[i] = a[i - 1] - 1;
    if (a[i] == 0)
      ans = max(ans, i);
    else {
      if (vis[a[i] + 100000] == 0)
        vis[a[i] + 100000] = i;
      else
        ans = max(ans, i - vis[a[i] + 100000]);
    }
  }
  cout << ans << endl;
  return 0;
}
