#include <bits/stdc++.h>
using namespace std;
string dna = "ACTG";
int solve(string word) {
  int custo = 0;
  for (int i = 0; i < 4; i++) {
    int esq = max(word[i], dna[i]) - min(word[i], dna[i]);
    int dir = 26 - esq;
    custo += min(esq, dir);
  }
  return custo;
}
int main() {
  int N;
  cin >> N;
  string word;
  cin >> word;
  int menor = (int)1e9;
  for (int i = 0; i <= N - 4; i++) {
    string chk = word.substr(i, 4);
    menor = min(menor, solve(chk));
  }
  cout << menor << '\n';
  return 0;
}
