#include <bits/stdc++.h>
using namespace std;
const int INF = 1500;
int main() {
  int n;
  scanf("%d\n", &n);
  string s;
  cin >> s;
  int ans = INF;
  int cur = 0;
  for (int i = 0; i <= n - 4; i++) {
    cur = 0;
    if ((int)s[i] <= 77)
      cur += (int)s[i] - 65;
    else
      cur += 91 - (int)s[i];
    if ((int)s[i + 1] <= 80 && (int)s[i + 1] >= 67)
      cur += (int)s[i + 1] - 67;
    else if ((int)s[i + 1] <= 90 && (int)s[i + 1] > 80)
      cur += 93 - (int)s[i + 1];
    else
      cur += 67 - (int)s[i + 1];
    if ((int)s[i + 2] >= 71 && (int)s[i + 2] <= 84)
      cur += 84 - (int)s[i + 2];
    else if ((int)s[i + 2] < 71)
      cur += (int)s[i + 2] - 65 + 7;
    else
      cur += (int)s[i + 2] - 84;
    if ((int)s[i + 3] >= 71 && (int)s[i + 3] <= 84)
      cur += (int)s[i + 3] - 71;
    else if ((int)s[i + 3] < 71)
      cur += 71 - (int)s[i + 3];
    else
      cur += 90 - (int)s[i + 3] + 7;
    ans = min(ans, cur);
  }
  printf("%d\n", ans);
  return 0;
}
