#include <bits/stdc++.h>
using namespace std;
long long solve(string a) {
  string b = "ACTG";
  long long cnt = 0;
  for (long long i = 0; i < 4; i++)
    cnt += min(abs(a[i] - b[i]), 26 - abs(a[i] - b[i]));
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long minm = LLONG_MAX;
  for (long long i = 0; i < n - 3; i++) {
    string a;
    for (long long j = i; j < i + 4; j++) a += s[j];
    long long cnt = solve(a);
    minm = min(minm, cnt);
  }
  cout << minm;
  return 0;
}
