#include <bits/stdc++.h>
using namespace std;
int a[100005];
unordered_map<int, int> mymap;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int i;
  for (i = 0; i < n; i++) a[i] = s[i] - '0';
  int ans = 0, tsum = 0;
  mymap[0] = -1;
  for (i = 0; i < n; i++) {
    if (a[i] == 1)
      tsum += a[i];
    else
      tsum += (-1);
    if (mymap.find(tsum) != mymap.end()) {
      ans = max(ans, i - mymap[tsum]);
    } else
      mymap[tsum] = i;
  }
  cout << ans << '\n';
  return 0;
}
