#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = INT_MAX, cur = 0;
  string tar = "ACTG";
  for (int i = 0; i < n - (tar.size() - 1); i++) {
    cur = 0;
    for (int j = 0; j < tar.size(); j++) {
      int a = tar[j] - 'A', b = s[i + j] - 'A';
      cur += min(abs(a - b), min((25 - b) + a + 1, b + (25 - a) + 1));
    }
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}
