#include <bits/stdc++.h>
using namespace std;
string ch;
long long n, x;
string gen = "ACTG";
int main() {
  cin >> n;
  cin >> ch;
  long long ans = 1e18;
  for (int i = 0; i <= n - 4; i++) {
    string sh = ch.substr(i, 4);
    long long res = 0;
    for (int j = 0; j < 4; j++) {
      x = ch[i + j] - gen[j];
      res += min(abs(x), 26 - abs(x));
    }
    ans = min(ans, res);
  }
  cout << ans;
  return 0;
}
