#include <bits/stdc++.h>
using namespace std;
ifstream f("1.in");
int n;
char s[55];
int ans = 0x3f3f3f3f, sum;
int get(char a, char b) {
  int x = a - 'A';
  int y = b - 'A';
  return min(abs(x - y), 26 - abs(x - y));
}
int main() {
  cin >> n >> s;
  for (int i = 0; i < n - 3; i++) {
    sum = get(s[i], 'A') + get(s[i + 1], 'C') + get(s[i + 2], 'T') +
          get(s[i + 3], 'G');
    ans = min(ans, sum);
  }
  cout << ans;
  return 0;
}
