#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  int d[4] = {0, 2, 19, 6};
  int a[n];
  for (int i = 0; i < n; i++) a[i] = str[i] - 'A';
  int mi = INT_MAX;
  for (int i = 0; i < n - 3; i++) {
    int ans = 0;
    ans += min(abs(str[i] - 'A'), 26 - abs(str[i] - 'A'));
    ans += min(abs(str[i + 1] - 'C'), 26 - abs(str[i + 1] - 'C'));
    ans += min(abs(str[i + 2] - 'T'), 26 - abs(str[i + 2] - 'T'));
    ans += min(abs(str[i + 3] - 'G'), 26 - abs(str[i + 3] - 'G'));
    mi = min(ans, mi);
  }
  cout << mi << endl;
  return 0;
}
