#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7, N = 2e5 + 7;
const long long linf = 3e18 + 7, mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
int n;
string s;
int pref0[N], pref1[N], md[N];
map<int, int> pos;
int main() {
  cin >> n >> s;
  s = '$' + s;
  for (int i = 1; i <= n; i += 1) {
    pref0[i] = pref0[i - 1] + (s[i] == '0');
    pref1[i] = pref1[i - 1] + (s[i] == '1');
    md[i] = pref1[i] - pref0[i];
  }
  int ans = 0;
  pos[0] = 0;
  for (int i = 1; i <= n; i += 1) {
    if (pos[md[i]] || md[i] == 0) {
      ans = max(ans, i - pos[md[i]]);
    } else {
      pos[md[i]] = i;
    }
  }
  cout << ans;
  return 0;
}
