#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
const int MAXM = 100 + 10;
const int INF = 0x3f3f3f3f;
void File(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
inline long long fread(void) {
  long long ret = 0, op = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - '0';
  return ret * op;
}
long long n;
string a;
long long arr[MAXN];
inline void init(void) {
  n = fread();
  cin >> a;
  for (long long i = 1; i <= n; ++i) arr[i] = a[i - 1] - 'A' + 1;
}
string gene;
long long ans, g[MAXN];
inline void work(void) {
  gene = "ACTG";
  ans = INF;
  for (long long i = 1; i <= 4; ++i) g[i] = gene[i - 1] - 'A' + 1;
  for (long long i = 1; i <= n - 3; ++i) {
    long long now = 0;
    for (long long j = 0; j <= 3; ++j) {
      now += min(abs(g[j + 1] - arr[i + j]), 26 - abs(g[j + 1] - arr[i + j]));
    }
    ans = min(ans, now);
  }
  cout << ans;
}
int main() {
  init();
  work();
  return 0;
}
