#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, r = INT_MAX, ans = 0, a, c, b, d;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n - 3; i++) {
    ans = min(abs(s[i] - 'A'), 26 - abs(s[i] - 'A')) +
          min(abs(s[i + 1] - 'C'), 26 - abs(s[i + 1] - 'C')) +
          min(abs(s[i + 2] - 'T'), 26 - abs(s[i + 2] - 'T')) +
          min(abs(s[i + 3] - 'G'), 26 - abs(s[i + 3] - 'G'));
    r = min(r, ans);
  }
  cout << r;
  return 0;
}
