#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string gen = "ACTG";
  int sum = 10000;
  vector<bool> used_big(n, false);
  vector<bool> used_gen(4, false);
  for (int i = 0; i <= n - 4; i++) {
    int tmp_sum = 0;
    for (int j = 0; j < 4; j++) {
      int dif = abs(s[i + j] - gen[j]);
      if (26 - dif < dif) dif = 26 - dif;
      tmp_sum += dif;
    }
    if (tmp_sum < sum) sum = tmp_sum;
  }
  cout << sum;
}
