#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, sum = 0, mn = 5000, k = 0;
  string s;
  char a[4] = {'A', 'C', 'T', 'G'};
  cin >> n;
  cin >> s;
  for (i = 0; i < n - 3; i++) {
    sum = 0;
    k = 0;
    for (j = i; j < i + 4; j++) {
      sum += min(abs(s[j] - a[k]), abs(abs(s[j] - a[k]) - 26));
      k++;
    }
    mn = min(mn, sum);
  }
  cout << mn << endl;
  return 0;
}
