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