#include <bits/stdc++.h>
const int N = 50 + 5;
const int M = 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e6 + 7;
const double Exp = 1e-8;
const double PI = acos(-1);
using namespace std;
int n;
char s[N];
int dis(int now, int goal) {
  if (now > goal) {
    int temp = now;
    now = goal;
    goal = temp;
  }
  return (goal - now > 25 - goal + 1 + now) ? (25 - goal + 1 + now)
                                            : (goal - now);
}
int solve(int pos) {
  return dis(s[pos] - 'A', 0) + dis(s[pos + 1] - 'A', 'C' - 'A') +
         dis(s[pos + 2] - 'A', 'T' - 'A') + dis(s[pos + 3] - 'A', 'G' - 'A');
}
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  int ans = 120;
  for (int i = 0; i < n - 3; ++i) {
    int temp = solve(i);
    if (temp < ans) ans = temp;
  }
  printf("%d", ans);
}
