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