#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  string genom = "ACTG";
  int min_ans = INT_MAX;
  for (int i = 0; i + 3 < n; i++) {
    int p = i;
    int val = 0;
    int temp;
    for (int j = 0; j < 4; j++) {
      int a = str[p] - genom[j] > 0 ? str[p] - genom[j] : -(str[p] - genom[j]);
      a = min(a, 26 - a);
      val += a;
      p++;
    }
    min_ans = min(min_ans, val);
  }
  cout << min_ans << endl;
  return 0;
}
