#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string S, K = "ACTG";
  cin >> S;
  int ans = INT_MAX;
  for (int i = 0; i < n - 4 + 1; i++) {
    int kapa = 0;
    for (int j = 0; j < 4; j++) {
      int x = (K[j] - S[i + j] + 26) % 26;
      x = min(26 - x, x);
      kapa += x;
    }
    ans = min(kapa, ans);
  }
  cout << ans << endl;
  return 0;
}
