#include <bits/stdc++.h>
using namespace std;
int min_dist(char ch1, char ch2) {
  int d1 = abs(ch1 - ch2);
  int d2 = 26 - d1;
  return min(d1, d2);
}
int main(int argc, char** argv) {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int op = 0;
  int mn = INT_MAX;
  for (int i = 0; i < s.length() - 3; i++) {
    op = 0;
    op += min_dist('A', s[i]) + min_dist('C', s[i + 1]) +
          min_dist('T', s[i + 2]) + min_dist('G', s[i + 3]);
    mn = min(mn, op);
  }
  cout << mn;
  return 0;
}
