#include <bits/stdc++.h>
using namespace std;
int mcount(char mychar, char c) {
  int next, prev;
  next = max(mychar, c) - min(mychar, c);
  prev = (min(mychar, c) - max(mychar, c)) + 26;
  return min(prev, next);
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  int mini = 1000;
  for (int i = 0; i < n - 3; i++) {
    mini = min(mini, mcount(s[i], 'A') + mcount(s[i + 1], 'C') +
                         mcount(s[i + 2], 'T') + mcount(s[i + 3], 'G'));
  }
  cout << mini << endl;
  return 0;
}
