#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e6) + 11;
int n;
char s[maxn];
int dp[maxn];
int main() {
  register int i;
  scanf("%d", &n);
  scanf("%s", s);
  memset(dp, -1, sizeof(dp));
  dp[n] = 0;
  int cnt = 0, ans = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '0')
      cnt--;
    else
      cnt++;
    if (~dp[cnt + n])
      ans = max(ans, i + 1 - dp[cnt + n]);
    else
      dp[cnt + n] = i + 1;
  }
  cout << ans << endl;
  return 0;
}
