#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int arr[n + 1];
  arr[0] = 0;
  if (s[0] == '0')
    arr[1] = -1;
  else
    arr[1] = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == '0')
      arr[i + 1] = arr[i] - 1;
    else
      arr[i + 1] = arr[i] + 1;
  }
  map<int, vector<int>> m;
  for (int i = 0; i < n + 1; i++) {
    m[arr[i]].push_back(i);
  }
  int max = 0;
  for (auto p = m.begin(); p != m.end(); p++) {
    if (p == m.begin()) {
      max = m[p->first][m[p->first].size() - 1] - m[p->first][0];
    } else {
      if (max < m[p->first][m[p->first].size() - 1] - m[p->first][0])
        max = m[p->first][m[p->first].size() - 1] - m[p->first][0];
    }
  }
  cout << max;
  return 0;
}
