#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  string second;
  ll M = 2600, cnt = 0, n;
  cin >> n >> second;
  for (ll i = 0; i < n - 3; i++) {
    cnt += min(abs(second[i] - 'A'), 'Z' - second[i] + 1);
    if (second[i + 1] <= 'C') {
      cnt += 'C' - second[i + 1];
    } else {
      cnt += min(second[i + 1] - 'C', 'Z' - second[i + 1] + 3);
    }
    if (second[i + 2] >= 'T') {
      cnt += second[i + 2] - 'T';
    } else {
      cnt += min('T' - second[i + 2], (second[i + 2] - 'A') + 'Z' - 'T' + 1);
    }
    if (second[i + 3] <= 'G') {
      cnt += 'G' - second[i + 3];
    } else {
      cnt += min(second[i + 3] - 'G', 'Z' - second[i + 3] + 7);
    }
    M = min(M, cnt);
    cnt = 0;
  }
  cout << M;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
