#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int max(int a, int b) {
  if (a < b) return b;
  return a;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  map<int, int> m;
  long long sum = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      sum++;
    else
      sum--;
    if (sum == 0)
      ans = max(ans, i + 1);
    else if (m.find(sum) != m.end()) {
      ans = max(ans, i - m[sum]);
    } else
      m[sum] = i;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
