#include <bits/stdc++.h>
using namespace std;
int f(char c, char x) {
  int a1 = abs(int(c) - int(x));
  int a2 = abs(abs(int(c) - int(x)) - 26);
  return (a1 < a2) ? a1 : a2;
}
int main() {
  string s;
  int n;
  cin >> n;
  cin >> s;
  vector<int> arr(n, 0);
  int min = 666;
  for (int i = 0; i < n - 3; i++) {
    int cur =
        f(s[i], 'A') + f(s[i + 1], 'C') + f(s[i + 2], 'T') + f(s[i + 3], 'G');
    if (cur < min) min = cur;
  }
  cout << min;
  return 0;
}
