#include <bits/stdc++.h>
using namespace std;
int n;
char s[100005];
int arr[100005];
map<int, int> mp;
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    arr[i] = s[i] == '0' ? -1 : 1;
  }
  mp.clear();
  int tmp = 0, maxx = 0;
  for (int i = 1; i <= n; i++) {
    tmp += arr[i];
    if (tmp != 0 && !mp[tmp])
      mp[tmp] = i;
    else {
      if (i - mp[tmp] > maxx) maxx = i - mp[tmp];
    }
  }
  printf("%d\n", maxx);
  return 0;
}
