#include <bits/stdc++.h>
using namespace std;
long long n, m, k, y, z, l, i, j, x;
map<long long, long long> f;
long long a[500500], b[500500], c[500500];
long long used[500500];
string pat = "ACTG";
long long get(string s) {
  long long ans = 0;
  for (int i = 0; i < 4; i++)
    ans += min((s[i] - pat[i] + 26) % 26, 26 - (s[i] - pat[i] + 26) % 26);
  return ans;
}
int main() {
  srand(time(0));
  cin >> n;
  string s;
  cin >> s;
  l = 3902582;
  for (int i = 0; i + 4 <= n; i++) {
    l = min(l, get(s.substr(i, 4)));
  }
  cout << l << endl;
  return 0;
}
