#include <bits/stdc++.h>
using namespace std;
long long ceila(long long x, long long y) {
  long long k = x / y;
  if (y * k != x) k++;
  return k;
}
int32_t main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  n = s.size();
  long long mina = 10e9 + 7;
  for (long long i = 0; i < n - 3; i++) {
    long long ans = 0;
    long long k1 = s[i];
    long long k2 = s[i + 1];
    long long k3 = s[i + 2];
    long long k4 = s[i + 3];
    ans += min(abs(k1 - 65), 26 - abs(k1 - 65));
    ans += min(abs(k2 - 67), 26 - abs(k2 - 67));
    ans += min(abs(k3 - 84), 26 - abs(k3 - 84));
    ans += min(abs(k4 - 71), 26 - abs(k4 - 71));
    if (ans < mina) {
      mina = ans;
    }
  }
  cout << mina << endl;
  return 0;
}
