#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
bool pr[1000007];
void sieve() {
  pr[0] = 1;
  pr[1] = 1;
  for (int i = 2; i < sqrt(1000007); i++) {
    for (int j = 2 * i; j <= 1000007; j += i) {
      pr[j] = 1;
    }
  }
}
long long differ(long long a, long long b) {
  a = a - 65;
  b = b - 65;
  long long d = min(abs(a - b), min(a, b) + (25 - max(a, b)) + 1);
  return d;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, a, b, c;
  string q, r, s;
  vector<long long> m, p;
  cin >> t;
  char d;
  int arr[4];
  arr[0] = (int)('A');
  arr[1] = (int)('C');
  arr[2] = (int)('T');
  arr[3] = (int)('G');
  vector<char> v;
  a = 1000000007;
  long long n = t;
  while (n--) {
    cin >> d;
    v.push_back(d);
  }
  for (long long i = 0; (i + 3) < t; i++) {
    b = 0;
    for (int j = int(0); j <= int(3); j++) {
      b += differ((int)(arr[j]), (int)v[i + j]);
    }
    a = min(a, b);
  }
  cout << a;
  return 0;
}
