#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
char s[N];
int cost(char a, char b) { return min(abs(b - a), 26 - abs(b - a)); }
int main() {
  int ans = 1e9;
  int n;
  cin >> n;
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) {
    int j = i + 1, k = j + 1, t = k + 1;
    if (t > n) continue;
    ans = min(ans, cost(s[i], 'A') + cost(s[j], 'C') + cost(s[k], 'T') +
                       cost(s[t], 'G'));
  }
  cout << ans;
}
