#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
int main() {
  long long int num = 0, i, len;
  long long int ans = 0;
  string str;
  cin >> len;
  cin >> str;
  mp[0] = len;
  for (i = len - 1; i >= 0; i--) {
    if (str[i] == '1')
      num++;
    else
      num--;
    if (mp[num] == 0) {
      mp[num] = i;
    } else {
      ans = max(ans, mp[num] - i);
    }
  }
  cout << ans << endl;
}
