#include <bits/stdc++.h>
using namespace std;
int cha(char a, char b) {
  if (a < b) swap(a, b);
  return min(a - b, b + 26 - a);
}
int main() {
  int n, i, Min = 999999999;
  string s;
  cin >> n >> s;
  for (i = 0; i < n - 3; i++) {
    Min = min(Min, cha(s[i], 'A') + cha(s[i + 1], 'C') + cha(s[i + 2], 'T') +
                       cha(s[i + 3], 'G'));
  }
  cout << Min;
  return 0;
}
