#include <bits/stdc++.h>
using namespace std;
int f[100][5];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    f[i][1] = min(abs(s[i] - 26 - 'A'), abs(s[i] - 'A'));
    f[i][2] = min(abs(s[i] - 26 - 'C'), abs(s[i] - 'C'));
    f[i][3] = min(abs(s[i] - 26 - 'T'), abs(s[i] - 'T'));
    f[i][4] = min(abs(s[i] - 26 - 'G'), abs(s[i] - 'G'));
    f[i][1] = min(abs(s[i] + 26 - 'A'), f[i][1]);
    f[i][2] = min(abs(s[i] + 26 - 'C'), f[i][2]);
    f[i][3] = min(abs(s[i] + 26 - 'T'), f[i][3]);
    f[i][4] = min(abs(s[i] + 26 - 'G'), f[i][4]);
  }
  int minx = 1000;
  for (int i = 0; i < s.size() - 3; i++) {
    minx = min(minx, f[i][1] + f[i + 1][2] + f[i + 2][3] + f[i + 3][4]);
  }
  cout << minx << endl;
  return 0;
}
