#include <bits/stdc++.h>
using namespace std;
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
int get(string s) {
  int ans = 0;
  ans += min(abs(s[0] - 'A'), 26 - abs(s[0] - 'A'));
  ans += min(abs(s[1] - 'C'), 26 - abs(s[1] - 'C'));
  ans += min(abs(s[2] - 'T'), 26 - abs(s[2] - 'T'));
  ans += min(abs(s[3] - 'G'), 26 - abs(s[3] - 'G'));
  return ans;
}
void solve() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 1e5 + 7;
  for (int i = 0; i <= n - 4; i++) {
    ans = min(ans, get(s.substr(i, 4)));
  }
  cout << ans << endl;
}
int main() { solve(); }
