#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
const string genome = "ACTG";
int distance(char c1, char c2) {
  if (c2 < c1) swap(c2, c1);
  return min(c2 - c1, 26 - (c2 - c1));
}
int distance(string a, string b) {
  int ans = 0;
  for (int i = 0; i < int(a.size()); i++) ans += distance(a[i], b[i]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(12);
  cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = INT_MAX;
  for (int i = 0; i < int(n - 4 + 1); i++)
    (ans) = min((ans), (distance(genome, s.substr(i, 4))));
  cout << ans << endl;
}
