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