#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, t, res = 10000, i, t2, t3;
  cin >> n;
  string s;
  cin >> s;
  for (i = 3; i < s.size(); i++) {
    t = s[i - 3] - 'A';
    if (t < 0) t *= -1;
    if (t > 26) t = 52 - t;
    t2 = 26 - (s[i - 3] - 'A');
    if (t2 < 0) t2 *= (-1);
    if (t2 > 26) t2 = 52 - t2;
    t3 = min(t, t2);
    t = s[i - 2] - 'C';
    if (t < 0) t *= -1;
    if (t > 52) t = 52 - t;
    t2 = 26 - (s[i - 2] - 'C');
    if (t2 < 0) t2 *= -1;
    if (t2 > 26) t2 = 52 - t2;
    t3 += min(t, t2);
    t = s[i - 1] - 'T';
    if (t < 0) t *= -1;
    if (t > 26) t = 52 - t;
    t2 = 26 - (s[i - 1] - 'T');
    if (t2 < 0) t2 *= -1;
    if (t2 > 26) t2 = 52 - t2;
    t3 += min(t, t2);
    t = s[i] - 'G';
    if (t < 0) t *= -1;
    if (t > 26) t = 52 - t;
    t2 = 26 - (s[i] - 'G');
    if (t2 < 0) t2 *= -1;
    if (t2 > 26) t2 = 52 - t2;
    t3 += min(t, t2);
    res = min(t3, res);
  }
  cout << res << endl;
}
