#include <bits/stdc++.h>
using namespace std;
int n;
string a;
constexpr char t[4] = {'A', 'C', 'T', 'G'};
int best = INT_MAX;
int main() {
  cin >> n;
  cin >> a;
  for (int i = 0; i < n - 3; ++i) {
    int cur = 0;
    for (int j = 0; j < 4; ++j) {
      int temp = min(abs(t[j] - a[i + j]), abs(t[j] + 26 - a[i + j]));
      temp = min(temp, abs(t[j] - a[i + j] - 26));
      cur += temp;
    }
    best = min(best, cur);
  }
  cout << best;
  return 0;
}
