#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, j, c = 0;
  cin >> n;
  string s;
  cin >> s;
  string g = "ACTG";
  int ans = 1000;
  for (i = 0; i <= n - 4; i++) {
    c = 0;
    for (j = i; j < i + 4; j++) {
      int x = abs(s[j] - g[j - i]);
      x = min(x, 26 - x);
      c += x;
    }
    ans = min(ans, c);
  }
  cout << ans;
  return 0;
}
