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