#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 50, MOD = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  long long n;
  cin >> n >> s;
  long long ans1 = INT_MAX;
  for (long long i = 0; i < s.size() - 3; i++) {
    char c = s[i];
    long long kol = 0, kol1 = 0;
    while (true) {
      if (c == 'A') break;
      kol++;
      if (c == 'Z') {
        c = 'A';
      } else
        c++;
    }
    c = s[i];
    while (true) {
      if (c == 'A') break;
      kol1++;
      if (c == 'A') {
        c = 'Z';
      } else
        c--;
    }
    long long ans = 0;
    ans += min(kol, kol1);
    kol = 0, kol1 = 0;
    c = s[i + 1];
    while (true) {
      if (c == 'C') break;
      kol++;
      if (c == 'Z') {
        c = 'A';
      } else
        c++;
    }
    c = s[i + 1];
    while (true) {
      if (c == 'C') break;
      kol1++;
      if (c == 'A') {
        c = 'Z';
      } else
        c--;
    }
    ans += min(kol, kol1);
    kol = 0, kol1 = 0;
    c = s[i + 2];
    while (true) {
      if (c == 'T') break;
      kol++;
      if (c == 'Z') {
        c = 'A';
      } else
        c++;
    }
    c = s[i + 2];
    while (true) {
      if (c == 'T') break;
      kol1++;
      if (c == 'A') {
        c = 'Z';
      } else
        c--;
    }
    ans += min(kol, kol1);
    kol = kol1 = 0;
    c = s[i + 3];
    while (true) {
      if (c == 'G') break;
      kol++;
      if (c == 'Z') {
        c = 'A';
      } else
        c++;
    }
    c = s[i + 3];
    while (true) {
      if (c == 'G') break;
      kol1++;
      if (c == 'A') {
        c = 'Z';
      } else
        c--;
    }
    ans += min(kol, kol1);
    ans1 = min(ans, ans1);
  }
  cout << ans1;
}
