#include <bits/stdc++.h>
using namespace std;
int N;
string s;
int dist(char c1, char c2) {
  int ans = abs((int)(c1 - c2));
  ans = min(ans, 26 - ans);
  return ans;
}
int main() {
  getline(cin, s);
  N = stoi(s);
  getline(cin, s);
  int ans = 1000000;
  for (int i = 0; i <= N - 4; i++) {
    int t = 0;
    t += dist(s.at(i), 'A');
    t += dist(s.at(i + 1), 'C');
    t += dist(s.at(i + 2), 'T');
    t += dist(s.at(i + 3), 'G');
    ans = min(ans, t);
  }
  cout << ans << endl;
}
