#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, mx = 0, a = 0, b = 0, cntA = 0, cntB = 0, ans = 0;
  string s;
  map<long long, long long> m;
  cin >> n >> s;
  m[0] = 0;
  for (long long i = 1; i <= n; i++) {
    if (s[i - 1] == '0')
      cntA++;
    else
      cntB++;
    long long x = cntA - cntB;
    if (m.find(x) == m.end())
      m[x] = i;
    else
      ans = max(ans, i - m[x]);
  }
  cout << ans << "\n";
}
