#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
map<int, int> mp;
int main() {
  int n;
  string str;
  cin >> n >> str;
  for (int i = 1; i <= n; i++) {
    a[i] = str[i - 1] - '0';
    if (a[i] == 0) {
      a[i] = -1;
    }
  }
  int ans = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (mp[sum]) {
      ans = max(ans, i - mp[sum]);
    } else {
      mp[sum] = i;
    }
    if (sum == 0) {
      ans = max(ans, i);
    }
  }
  cout << ans << endl;
  return 0;
}
