#include <bits/stdc++.h>
using namespace std;
template <typename T>
T id(T b) {
  return b;
};
template <class It>
bool all(It f, It l) {
  return std::all_of(f, l, id<bool>);
}
template <class It>
bool any(It f, It l) {
  return std::any_of(f, l, id<bool>);
}
template <typename T>
void chmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chmin(T &x, T y) {
  if (x > y) x = y;
}
int n;
string s;
int diff(char c1, char c2) {
  if (c1 > c2) swap(c1, c2);
  return min(c2 - c1, c1 - 'A' + 'Z' - c2 + 1);
}
int main() {
  cin >> n >> s;
  int res = INT_MAX;
  for (int i = 0; i < n - 3; i++) {
    chmin(res, diff(s[i], 'A') + diff(s[i + 1], 'C') + diff(s[i + 2], 'T') +
                   diff(s[i + 3], 'G'));
  }
  cout << res << "\n";
  return 0;
}
