#include <bits/stdc++.h>
using namespace std;
int ara[10][1000];
char ch[1000], gen[] = "ACTG";
int main() {
  int n, m, i, j, k, a, b, c, x, y, z;
  cin >> n;
  scanf(" %s", ch);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 4; j++) {
      x = gen[j] - 'A';
      y = ch[i] - 'A';
      for (k = 0;; k++) {
        if ((y + k) % 26 == x) break;
      }
      z = k;
      y = ch[i] - 'A';
      for (k = 0;; k++, y--) {
        if (y < 0) y += 26;
        if (y % 26 == x) break;
      }
      z = min(z, k);
      ara[j][i] = z;
    }
  }
  z = 1000000000;
  for (i = 0; i <= n - 4; i++) {
    x = ara[0][i] + ara[1][i + 1] + ara[2][i + 2] + ara[3][i + 3];
    z = min(z, x);
  }
  cout << z << endl;
}
