#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, cek1, cek2, cek3, cek4, min = 999999, temp;
  char j = 'A', k = 'C', l = 'T', m = 'G';
  cin >> a;
  string str;
  cin >> str;
  for (int i = 0; i <= a - 4; i++) {
    cek1 = abs(int(j) - int(str[i]));
    if (cek1 > 13) cek1 = 26 - cek1;
    cek2 = abs(int(k) - int(str[i + 1]));
    if (cek2 > 13) cek2 = 26 - cek2;
    cek3 = abs(int(l) - int(str[i + 2]));
    if (cek3 > 13) cek3 = 26 - cek3;
    cek4 = abs(int(m) - int(str[i + 3]));
    if (cek4 > 13) cek4 = 26 - cek4;
    temp = cek1 + cek2 + cek3 + cek4;
    if (temp < min) min = temp;
  }
  cout << min;
}
