#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, w, k = 0;
  string s, d;
  d = "ACTG";
  w = 'A' + 'C' + 'T' + 'G';
  int a = w;
  cin >> n >> s;
  int b = n - 4;
  int sum[n - 4];
  for (i = 0; i <= n - 4; i++) {
    sum[i] = 0;
    for (j = i; j < i + 4; j++) {
      k = 0;
      if (abs(s.at(j) - d.at(j - i)) > 13)
        k = 26 - abs(s.at(j) - d.at(j - i));
      else
        k = abs(s.at(j) - d.at(j - i));
      sum[i] = sum[i] + k;
    }
    a = min(a, sum[i]);
  }
  cout << a;
  return 0;
}
