#include <bits/stdc++.h>
using namespace std;
int dis(char a, char b) {
  if (a > b) swap(b, a);
  return min(b - a, a + 26 - b);
}
string tmp = "ACTG";
int main() {
  int n;
  scanf("%d", &n);
  string s;
  cin >> s;
  int mn = INT_MAX;
  for (int i = 0; i + 4 - 1 < n; i++) {
    int now = 0;
    for (int j = i, k = 0; k < 4; j++, k++) {
      now += dis(s[j], tmp[k]);
    }
    mn = min(mn, now);
  }
  printf("%d\n", mn);
  return 0;
}
