#include <bits/stdc++.h>
using namespace std;
const int md = (int)1e9 + 7;
const int siz = 300005;
long long arr[siz];
long long n, m, l;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> n;
  cin >> s;
  char c[4] = {'A', 'C', 'T', 'G'};
  int m = INT_MAX;
  for (int i = 0; i < n - 3; i++) {
    int k = 0;
    for (int z = 0; z < 4; z++) {
      k += min(26 - abs(s[i + z] - c[z]), abs(s[i + z] - c[z]));
    }
    m = min(k, m);
  }
  cout << m;
}
