#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, count = INT_MAX;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i <= n - 4; i++) {
    int lcount = 0;
    lcount =
        lcount + min(abs(int(s[i]) - int('A')), 26 - abs(int(s[i]) - int('A')));
    lcount = lcount + min(abs(int(s[i + 1]) - int('C')),
                          26 - abs(int(s[i + 1]) - int('C')));
    lcount = lcount + min(abs(int(s[i + 2]) - int('T')),
                          26 - abs(int(s[i + 2]) - int('T')));
    lcount = lcount + min(abs(int(s[i + 3]) - int('G')),
                          26 - abs(int(s[i + 3]) - int('G')));
    count = min(count, lcount);
  }
  cout << count << endl;
  return 0;
}
