#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
string s;
char A[4] = {'A', 'C', 'T', 'G'};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  cin >> s;
  int ans = 1000000;
  for (int i = 0; i < s.size() - 3; i++) {
    int sum = 0;
    for (int j = 0; j < 4; j++) {
      char c = s[i + j];
      int mmin = 100;
      mmin = min(mmin, (c + 26 - A[j]) % 26);
      mmin = min(mmin, (A[j] + 26 - c) % 26);
      sum += mmin;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
