#include <bits/stdc++.h>
using namespace std;
const string genome = "ACTG";
int main() {
  string s;
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    char x;
    cin >> x;
    s.append(1, x);
  }
  int min_diff = 26 * genome.size();
  for (int i = 0; i < s.size() - genome.size() + 1; ++i) {
    int diff = 0;
    for (int j = 0; j < genome.size(); ++j) {
      int tmp = (int)abs(genome[j] - s[i + j]);
      diff += min(tmp, 26 - tmp);
    }
    min_diff = min(min_diff, diff);
  }
  cout << min_diff;
}
