#include <bits/stdc++.h>
using namespace std;
string t = "ACTG";
int ans = 1e9;
int test(string s) {
  int ret = 0;
  for (int i = 0; i < 4; i++) {
    int x = abs(s[i] - t[i]);
    if (x >= 13) {
      x = 26 - x;
    }
    ret += x;
  }
  return ret;
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n - 3; i++) {
    ans = min(ans, test(s.substr(i, 4)));
  }
  cout << ans;
}
