#include <bits/stdc++.h>
using namespace std;
long long int const N = 3e5 + 5;
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int i, j, l;
  long long int n;
  string s;
  cin >> n >> s;
  long long int ans = 1e5;
  for (i = 0; i + 3 < n; i++) {
    long long int x = 0;
    x = x +
        min(abs(s[i] - 'A'), min(abs(s[i] - 26 - 'A'), abs(s[i] + 26 - 'A')));
    x = x + min(abs(s[i + 1] - 'C'),
                min(abs(s[i + 1] - 26 - 'C'), abs(s[i + 1] + 26 - 'C')));
    x = x + min(abs(s[i + 2] - 'T'),
                min(abs(s[i + 2] - 26 - 'T'), abs(s[i + 2] + 26 - 'T')));
    x = x + min(abs(s[i + 3] - 'G'),
                min(abs(s[i + 3] - 26 - 'G'), abs(s[i + 3] + 26 - 'G')));
    ans = min(ans, x);
  }
  cout << ans << endl;
  return 0;
}
