#include <bits/stdc++.h>
using namespace std;
int mini = 100010;
int main() {
  string pattern = "ACTG", str;
  int n;
  cin >> n >> str;
  for (int i = 0; i < str.size() - 3; i++) {
    int temp = 0;
    for (int j = 0; j < 4; j++) {
      temp +=
          min(26 - abs(str[i + j] - pattern[j]), abs(str[i + j] - pattern[j]));
    }
    mini = min(mini, temp);
  }
  printf("%d", mini);
  return 0;
}
