#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  long long n, i = 0;
  cin >> n;
  cin >> s;
  long long ans = 10000;
  while (i + 4 <= n) {
    long long sum = 0;
    long long d = abs(int(s[i]) - 'A');
    sum += min(d, 26 - d);
    d = abs(int(s[i + 1]) - 'C');
    sum += min(d, 26 - d);
    d = abs(int(s[i + 2]) - 'T');
    sum += min(d, 26 - d);
    d = abs(int(s[i + 3]) - 'G');
    sum += min(d, 26 - d);
    ans = min(ans, sum);
    i++;
  }
  cout << ans;
}
