#include <bits/stdc++.h>
using namespace std;
string s;
int l;
int ans = 0x3f3f3f3f;
int main() {
  cin >> l >> s;
  for (int i = 0; i + 3 < l; ++i) {
    int sum = 0;
    sum += min(abs(s[i] - 'A'), min(s[i], 'A') + 26 - max(s[i], 'A'));
    sum +=
        min(abs(s[i + 1] - 'C'), min(s[i + 1], 'C') + 26 - max(s[i + 1], 'C'));
    sum +=
        min(abs(s[i + 2] - 'T'), min(s[i + 2], 'T') + 26 - max(s[i + 2], 'T'));
    sum +=
        min(abs(s[i + 3] - 'G'), min(s[i + 3], 'G') + 26 - max(s[i + 3], 'G'));
    ans = min(ans, sum);
  }
  printf("%d", ans);
}
