#include <bits/stdc++.h>
using namespace std;
int rec(char v, char v1) {
  if (v1 < v) swap(v1, v);
  int k = abs(v1 - v);
  int j = 26 - (v1 - 64) + v - 65 + 1;
  return min(k, abs(j));
}
long long i, j, k, l, n, m;
long long a[200005], c[200005], d[200005];
pair<long long, long long> b[200005];
string s, s1;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> s;
  s = ' ' + s;
  s1 = "ACTG";
  m = 1e5;
  for (i = 1; i <= s.size() - 4 + 1; i++) {
    l = rec(s1[0], s[i]) + rec(s1[1], s[i + 1]) + rec(s1[2], s[i + 2]) +
        rec(s1[3], s[i + 3]);
    m = min(m, l);
  }
  cout << m;
}
