#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i, j = 0, p, q, n, m, a, b, k, r, c = 1000000007, x1, x2, x3, x4, y1, y2,
         y3, y4, sum = 0;
  cin >> n;
  string s, s1;
  cin >> s;
  for (i = 0; i < n - 3; i++) {
    s1 = s.substr(i, 4);
    sum += min(abs(s1[0] - 'A'), 26 - abs(s1[0] - 'A'));
    sum += min(abs(s1[1] - 'C'), 26 - abs(s1[1] - 'C'));
    sum += min(abs(s1[2] - 'T'), 26 - abs(s1[2] - 'T'));
    sum += min(abs(s1[3] - 'G'), 26 - abs(s1[3] - 'G'));
    c = min(sum, c);
    sum = 0;
  }
  cout << c;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
}
