#include <bits/stdc++.h>
using namespace std;
int dp[200020];
int ans = 0;
int sum = 100010;
int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  memset(dp, -1, sizeof(dp));
  dp[sum] = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == '0') {
      sum--;
    } else {
      sum++;
    }
    if (dp[sum] == -1) {
      dp[sum] = i + 1;
    } else {
      ans = max(ans, i + 1 - dp[sum]);
    }
  }
  cout << ans << endl;
  return 0;
}
