#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
  int n;
  int i;
  int sum = 0;
  int maxx = 0;
  string str;
  cin >> n;
  cin >> str;
  int pp = 100000;
  memset(a, -1, sizeof(a));
  for (i = 0; i < n; i++) {
    if (str[i] == '1')
      sum++;
    else
      sum--;
    if (a[sum + pp] == -1 && sum != 0) {
      a[sum + pp] = i;
    } else {
      maxx = max(maxx, i - a[sum + pp]);
    }
  }
  cout << maxx;
}
