#include <bits/stdc++.h>
const int Inf = 2e9;
long long LINF = (long long)4e18;
using namespace std;
long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1e9;
  for (int i = 0; i < n - 3; ++i) {
    int a = 0;
    a += min(abs(s[i] - 'A'), 26 - abs(s[i] - 'A'));
    a += min(abs(s[i + 1] - 'C'), 26 - abs(s[i + 1] - 'C'));
    a += min(abs(s[i + 2] - 'T'), 26 - abs(s[i + 2] - 'T'));
    a += min(abs(s[i + 3] - 'G'), 26 - abs(s[i + 3] - 'G'));
    ans = min(ans, a);
  }
  cout << ans;
  return 0;
}
