#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, c = 0, max = 0, b[200001], q, k = 100000;
  string a;
  cin >> n;
  cin >> a;
  for (i = 0; i < 200001; i++) b[i] = -2;
  b[k] = -1;
  for (i = 0; i < n; i++) {
    if (a[i] == '1')
      c++;
    else
      c--;
    if (b[k + c] == -2)
      b[k + c] = i;
    else {
      q = i - b[k + c];
      if (q > max) max = q;
    }
  }
  cout << (max);
  return 0;
}
