#include <bits/stdc++.h>
using namespace std;
int arr[100005];
map<int, int> mp;
int main() {
  int n;
  scanf("%d", &n);
  getchar();
  char c;
  int sum = 0;
  int Max = 0;
  mp[0] = -1;
  for (int i = 0; i < n; i++) {
    scanf("%c", &c);
    if (c == '0')
      sum += -1;
    else
      sum += 1;
    arr[i] = sum;
    if (mp.count(sum))
      Max = max(Max, i - mp[sum]);
    else
      mp[sum] = i;
  }
  cout << Max;
  return 0;
}
