#include <bits/stdc++.h>
using namespace std;
int mp[200010];
int vis[200010];
int main() {
  int len;
  scanf("%d", &len);
  string s;
  cin >> s;
  int i;
  int sum = 100000;
  int ans = 0;
  mp[100000] = -1;
  vis[100000] = 1;
  for (i = 0; i < len; i++) {
    if (s[i] == '0') sum--;
    if (s[i] == '1') sum++;
    if (vis[sum] == 0) {
      mp[sum] = i;
      vis[sum] = 1;
    } else
      ans = max(ans, i - mp[sum]);
  }
  printf("%d\n", ans);
  return 0;
}
