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