#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
void run() {
  int n, ans = inf;
  string s;
  cin >> n >> s;
  static int dp[1000][1000][2];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < 2; k++) dp[i][j][k] = inf;
  for (int len = 1; len <= n; len++)
    for (int l = 0; l < n - len + 1; l++) {
      int r = l + len - 1;
      if (len == 1) dp[l][r][s[l] == '1'] = 0;
      for (int k = 0; k < 2; k++) {
        if (l > 0)
          dp[l - 1][r][1 - k] =
              min(dp[l - 1][r][1 - k], dp[l][r][k] + (k == s[l - 1] - '0'));
        if (l > 1 && s[l - 1] == s[l - 2])
          dp[l - 2][r][k] = min(dp[l - 2][r][k], dp[l][r][k] + 1);
        if (r < n - 1)
          dp[l][r + 1][k] =
              min(dp[l][r + 1][k],
                  dp[l][r][k] + ((l + r + k) % 2 == s[r + 1] - '0'));
        if (r < n - 2 && s[r + 1] == s[r + 2])
          dp[l][r + 2][k] = min(dp[l][r + 2][k], dp[l][r][k] + 1);
      }
    }
  ans = min(dp[0][n - 1][0], dp[0][n - 1][1]);
  cout << (ans == inf ? -1 : ans) << endl;
}
int main() { run(); }
