#include <bits/stdc++.h>
using namespace std;
bool prime(int n) {
  for (int i = 2; i <= (n / i); i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
int binarySearchCount(int arr[], int n, int b) {
  int left = 0;
  int right = n - 1;
  int count = 0;
  while (left <= right) {
    int mid = (right + left) / 2;
    if (arr[mid] <= b) {
      count = mid + 1;
      left = mid + 1;
    } else
      right = mid - 1;
  }
  return count;
}
bool tonmoy(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
    return 0;
  return 1;
}
int area(int x1, int x2, int y1, int y2, int z1, int z2) {
  int pok =
      (x1 * y2) + (y1 * z2) + (z1 * x2) - (y1 * x2) - (z1 * y2) - (x1 * z2);
  if (pok < 0) {
    pok = (-1) * pok;
  }
  return pok;
}
int powerchecker(int n) {
  while (n != 1) {
    if (n % 2 != 0) {
      return 0;
    } else {
      n = n / 2;
    }
  }
  return 1;
}
int main() {
  int n;
  cin >> n;
  char ch[n + 1];
  scanf("%s", ch);
  vector<int> v;
  for (int i = 0; i < n - 3; i++) {
    int cnt = 0;
    if (ch[i] > 65) {
      if (ch[i] - 65 <= 13) {
        cnt = cnt + (ch[i] - 65);
      } else {
        cnt = cnt + 26 - (ch[i] - 65);
      }
    }
    if (ch[i + 1] > 67) {
      if (ch[i + 1] - 67 <= 13) {
        cnt = cnt + (ch[i + 1] - 67);
      } else {
        cnt = cnt + 26 - (ch[i + 1] - 67);
      }
    } else if (ch[i + 1] < 67) {
      cnt = cnt + (67 - ch[i + 1]);
    }
    if (ch[i + 2] > 84) {
      cnt = cnt + (ch[i + 2] - 84);
    } else if (ch[i + 2] < 84) {
      if (84 - ch[i + 2] <= 13) {
        cnt = cnt + (84 - ch[i + 2]);
      } else {
        cnt = cnt + 26 - (84 - ch[i + 2]);
      }
    }
    if (ch[i + 3] < 71) {
      cnt = cnt + (71 - ch[i + 3]);
    } else if (ch[i + 3] > 71) {
      if (ch[i + 3] - 71 <= 13) {
        cnt = cnt + (ch[i + 3] - 71);
      } else {
        cnt = cnt + 26 - (ch[i + 3] - 71);
      }
    }
    v.push_back(cnt);
  }
  sort(v.begin(), v.end());
  cout << v[0] << endl;
}
