#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<long long> g[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long i, j;
    long long ans = 1e16;
    for (int i = 0; i < n - 3; i++) {
      long long sm = 0, c = 0;
      for (int j = i; j < i + 4; j++) {
        if (c % 4 == 0) {
          sm += min(abs(s[j] - 'A'), abs(s[j] - 'Z') + 1);
        }
        if (c % 4 == 1) {
          sm += min(abs(s[j] - 'C'), abs(s[j] - 'Z') + 3);
        }
        if (c % 4 == 2) {
          sm += min(abs(s[j] - 'T'), abs(s[j] - 'A') + 7);
        }
        if (c % 4 == 3) {
          sm += min(abs(s[j] - 'G'), abs(s[j] - 'Z') + 7);
        }
        c++;
      }
      ans = min(ans, sm);
    }
    cout << ans << '\n';
  }
  return 0;
}
