#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mod2 = 998244353;
const long long mod3 = 10007;
const long long inf = 1e18 * 4;
const long double pai = acos(-1);
int n;
string s;
string x = "ACTG";
int calc(char a, char b) {
  if (a == b) return 0;
  if (a < b) {
    int ans1 = abs(a - b);
    int ans2 = abs(a - 'A') + 1;
    ans2 += abs('Z' - b);
    return min(ans1, ans2);
  }
  if (a > b) {
    int ans1 = abs(a - b);
    int ans2 = abs(a - 'Z') + 1;
    ans2 += abs('A' - b);
    return min(ans1, ans2);
  }
  return 0;
}
int main() {
  cin >> n >> s;
  int mn = 1e9;
  for (int i = 0; i < n - 3; i++) {
    int crnt = 0;
    for (int j = i; j < i + 4; j++) {
      crnt += calc(s[j], x[j - i]);
    }
    mn = min(mn, crnt);
  }
  cout << mn << endl;
}
