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