#include <bits/stdc++.h>
using namespace std;
string s;
string s1 = "ACTG";
int m(int y) {
  int ans = 0;
  for (int i = y; i < y + 4; i++) {
    int mm = min((s1[i - y] - 'A') + 26 - (s[i] - 'A'),
                 abs((s[i] - 'A') - (s1[i - y] - 'A')));
    ans += min(mm, 1 + (s[i] - 'A') + 25 - (s1[i - y] - 'A'));
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  int ans = 1000000;
  cin >> s;
  for (int i = 0; i < n - 3; i++) {
    ans = min(ans, m(i));
  }
  cout << ans << endl;
  return 0;
}
