#include <bits/stdc++.h>
using namespace std;
int mins(int a, int b) {
  if (a >= b)
    return b;
  else
    return a;
}
int main() {
  char s[55];
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  int cnt = 100000;
  int cnt1;
  int nn;
  for (int i = 0; i + 4 <= n; i++) {
    cnt1 = 0;
    nn = abs(s[i] - 'A');
    cnt1 += mins(nn, 26 - nn);
    nn = abs(s[i + 1] - 'C');
    cnt1 += mins(nn, 26 - nn);
    nn = abs(s[i + 2] - 'T');
    cnt1 += mins(nn, 26 - nn);
    nn = abs(s[i + 3] - 'G');
    cnt1 += mins(nn, 26 - nn);
    cnt = mins(cnt, cnt1);
  }
  cout << cnt;
  return 0;
}
