#include <bits/stdc++.h>
using namespace std;
string x = "ACTG";
int n;
string s;
int main() {
  cin >> n >> s;
  int mn = 1e6;
  for (int i = 0; i < n - 3; i++) {
    int sum = 0;
    for (int j = 0; j < 4; j++) {
      int a = 0, b = 0;
      char r = s[i + j];
      while (r != x[j]) {
        a++;
        r++;
        if (r > 'Z') r = 'A';
      }
      r = s[i + j];
      while (r != x[j]) {
        r--;
        b++;
        if (r < 'A') r = 'Z';
      }
      sum += min(a, b);
    }
    mn = min(sum, mn);
  }
  cout << mn;
  return 0;
}
