#include <bits/stdc++.h>
using namespace std;
int num[50][4];
int abs(int a) {
  if (a < 0) return a + 26;
  return a;
}
int miin(int a, int b) {
  if (a < b) return a;
  return b;
}
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  for (int i = 0; i < N; i++) {
    num[i][0] = min(abs(s[i] - 'A'), 26 - abs(s[i] - 'A'));
    num[i][1] = min(abs(s[i] - 'C'), 26 - abs(s[i] - 'C'));
    num[i][2] = min(abs(s[i] - 'T'), 26 - abs(s[i] - 'T'));
    num[i][3] = min(abs(s[i] - 'G'), 26 - abs(s[i] - 'G'));
  }
  int mian = 100000;
  for (int i = 0; i < N - 3; i++) {
    int sum = 0;
    for (int j = 0; j < 4; j++) {
      sum += num[i + j][j];
    }
    mian = miin(sum, mian);
  }
  cout << mian;
  return 0;
}
