#include <bits/stdc++.h>
using namespace std;
void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  int tc = 1;
  while (tc--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int temp, mini = 2000000007;
    string tr = "ACTG";
    vector<int> arr(n);
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      arr[i] = s[i] - 'A' + 1;
    }
    for (__typeof(n - 3) i = (0) - ((0) > (n - 3));
         i != (n - 3) - ((0) > (n - 3)); i += 1 - 2 * ((0) > (n - 3))) {
      temp = min(abs(s[i] - tr[0]), abs(26 - abs(s[i] - tr[0])));
      temp += min(abs(s[i + 1] - tr[1]), abs(26 - abs(s[i + 1] - tr[1])));
      temp += min(abs(s[i + 2] - tr[2]), abs(26 - abs(s[i + 2] - tr[2])));
      temp += min(abs(s[i + 3] - tr[3]), abs(26 - abs(s[i + 3] - tr[3])));
      mini = min(temp, mini);
    }
    cout << mini;
  }
  return 0;
}
