#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, mini = 1300, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.length() - 3; i++) {
    ans = 0;
    ans += min(abs('A' - s[i]), 26 - abs('A' - s[i]));
    ans += min(abs('C' - s[i + 1]), 26 - abs('C' - s[i + 1]));
    ans += min(abs('T' - s[i + 2]), 26 - abs('T' - s[i + 2]));
    ans += min(abs('G' - s[i + 3]), 26 - abs('G' - s[i + 3]));
    if (ans < mini) {
      mini = ans;
    }
  }
  cout << mini << endl;
}
