#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string str;
  cin >> n >> str;
  int sum, dif, minval = 2000000000;
  string gen = "ACTG";
  for (int i = 0; i <= n - 4; i++) {
    sum = 0;
    for (int j = 0; j < 4; j++)
      dif = abs(str[i + j] - gen[j]), sum += min(dif, 26 - dif);
    minval = min(minval, sum);
  }
  cout << minval << endl;
}
