import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class myFile
{
	public static void main(String args[])
	{
		Integer count=1;
		Map<Character,Integer> hashMap = new HashMap<Character,Integer>();
		Scanner sc = new Scanner(System.in);
		for(Character ch='A';ch<='Z';ch++)
		{
			hashMap.put(ch, count);
			count++;
		}

		Set<Integer>answer = new HashSet<Integer>();
		while(sc.hasNextInt())
		{
			Integer length = sc.nextInt();
			sc.nextLine();
			String str = sc.nextLine();
			answer.clear();
			for(int i=0;i<str.length()-3;i++)
			{
				Integer step=0;
				char ch1 = str.charAt(i);
				step+=getStep(hashMap, ch1, 'A');

				ch1 = str.charAt(i+1);
				step+=getStep(hashMap, ch1, 'C');

				ch1 = str.charAt(i+2);
				step+=getStep(hashMap, ch1, 'T');

				ch1 = str.charAt(i+3);
				step+=getStep(hashMap, ch1, 'G');

				answer.add(step);

			}
			Integer r = 2147483640;
			for(Integer set: answer)
			{
				r = Math.min(r,set);
			}
			System.out.println(r);
		}

	}

	private static Integer getStep(Map<Character, Integer> hashMap, char ch1, char ch2)
	{
		if(ch1>ch2)
		{
			char tmp = ch1;
			ch1 = ch2;
			ch2 = tmp;
		}

		int x =hashMap.get(ch1)-hashMap.get('A');
		int y = hashMap.get('Z')-hashMap.get(ch2);
		int diff = hashMap.get(ch2)-hashMap.get(ch1);
		int step = Math.min((x+y+1),diff);

		return step;
	}
}

import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class Main {

	//final boolean isDebug = true;
	final boolean isDebug = false;
	String fileName = "input.txt";
	FastScanner sc;
	PrintWriter out;
	final int MOD = (int)1e9+7;
	final int INF = Integer.MAX_VALUE / 2;

	void solve() throws Exception{
		int N = sc.nextInt();
		String S = sc.next();
		String P = "ACTG";
		int min = Integer.MAX_VALUE;
		for(int i = 0; i + 3 < N; i++){
			int cost = 0;
			for(int j = 0; j < 4; j++){
				int d = Math.abs(S.charAt(i+j) - P.charAt(j));
				cost += Math.min(d, 26-d);
			}
			min = Math.min(min, cost);
		}
		System.out.println(min);
	}

	/* end solve */

	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}

	void m() throws Exception {
		long S = System.currentTimeMillis();
		sc = (isDebug) ? new FastScanner(new FileInputStream(fileName)) : new FastScanner(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		if(isDebug){
			System.out.println("---Debug---");
			System.out.printf("%8d ms", (G-S));
		}
	}
	/* end main */
}
/* end Main */

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public String nextLine() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(b != 10) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

import java.io.*;

public class Codechef
{
	public static void main (String[] args) throws IOException
	{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=1;//Integer.parseInt(br.readLine().trim());
        while((t--)>0)
        {
                int n=Integer.parseInt(br.readLine().trim());
                String s=br.readLine().trim();
                int min=Integer.MAX_VALUE;
        		for(int i=0;i<n-3;i++)
        		{
        		    int temp=fun(s,i);
        		    if(min>temp)
        		        min=temp;
        		}
        	   System.out.println(min);
            }
	}
	static int fun(String s,int i)
    {

        int a=(int)Math.abs(s.charAt(i)-'A');
        int b=(int)Math.abs(s.charAt(i+1)-'C');
        int c=(int)Math.abs(s.charAt(i+2)-'T');
        int d=(int)Math.abs(s.charAt(i+3)-'G');
        if(a>(26-a))
            a=26-a;
        if(b>26-b)
            b=26-b;
        if(c>26-c)
            c=26-c;
        if(d>26-d)
            d=26-d;
        return a+b+c+d;
    }
}

import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Scanner;

import static java.lang.Integer.min;

public class TaskA {
    int n;
    String s;
    String t = "ACTG";

    public int cal(String a){
        int res = 0;
        for(int i=0; i<4; i++){
            int cai = a.charAt(i) - 'A';
            int cti = t.charAt(i) - 'A';
            int n = min((cti - cai + 26)%26 , (cai - cti + 26)%26);
            res += (n)%26;
        }
        return res;
    }

    public void solve() throws Exception{
        //System.setIn(new FileInputStream("inputs/a.in"));
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt(); s= sc.next();
        int res = 10000;
        for(int i=0; i<n-3; i++){
            res = min(res, cal(s.substring(i, i+4)));
        }
        System.out.println(res);
    }

    public static void main(String[] args) throws Exception{
        TaskA s = new TaskA();
        s.solve();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class PrBe {

	public static void main(String[] args) {
				InputStream inputStream = System.in;
				OutputStream outputStream = System.out;
				InputReader in = new InputReader(inputStream);
				PrintWriter out = new PrintWriter(outputStream);
				Task solver = new Task();
				solver.solve(1, in, out);
				out.close();
	}
	static class Task{

		int n;
		String s;
		public void solve(int t, InputReader in, PrintWriter out) {
			n = in.nextInt();
			char[] s = in.next().toCharArray();

			int mi = 9999;
			for(int i = 0; i< n-3; i++ ) {

				mi = Math.min(mi,root(s[i],'A')+root(s[i+1],'C')+root(s[i+2],'T')+root(s[i+3],'G'));
				//out.print(mi + " " +sa + " " +sc + " " +st + " " +sg);
			}
			out.print(mi);
		}
		public int root(char main, char to) {
			int dn,up;
			if(main == to ) return 0;
			if(main < to) {
				dn = to -main;
				up = 'Z' - to + main -'A' +1;
			}
			else  {
				dn = -to + main;
				up = 'Z' - main + to -'A' +1;
			}
			return Math.min(dn, up);
		}
	}

	static class InputReader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream),32768);
			tokenizer = null;
		}
		public String next() {
			while(tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				}catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    static void print(Object s){ System.out.print(s.toString()); }
    static void println(Object s){ System.out.println(s.toString()); }
    static void inputArr(int[] arr, int n){
        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
        }
    }
    static void printArr(int[] arr){
        for(int i=0;i<arr.length;i++){
            print(arr[i]+" ");
        }
    }
    static Scanner sc = new Scanner(System.in);
    static int gcd(int a, int b)
    {
        if (a == 0)
           return b;
        if (b == 0)
           return a;
        if (a == b)
            return a;
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n = sc.nextInt();
	    String a = sc.nextLine();
	    a = sc.nextLine();
	    int st = 0;
	    int min = Integer.MAX_VALUE;
	    int u =0;
	    for(int i=0;i<a.length()-3;i++){
	        u = Math.abs(a.charAt(i)-'A')>13?26-Math.abs(a.charAt(i)-'A'):Math.abs(a.charAt(i)-'A');

	         u += Math.abs(a.charAt(i+1)-'C')>13?26-Math.abs(a.charAt(i+1)-'C'):Math.abs(a.charAt(i+1)-'C');

	        u += Math.abs(a.charAt(i+2)-'T')>13?26-Math.abs(a.charAt(i+2)-'T'):Math.abs(a.charAt(i+2)-'T');

	        u += Math.abs(a.charAt(i+3)-'G')>13?26-Math.abs(a.charAt(i+3)-'G'):Math.abs(a.charAt(i+3)-'G');

	        if(u<min){
	            min = u;
	        }
	    }
	    print(min);
	}
}

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * Created by Julia on 01.04.2017.
 */
public class SolverA {

    public static void main(String[] args) throws IOException {
        new SolverA().run();
    }

    StringTokenizer stok;
    BufferedReader br;
    PrintWriter pw;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            stok = new StringTokenizer(br.readLine());
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    Map<Character, Integer> map = new HashMap<Character, Integer>();
    void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new OutputStreamWriter(System.out));
//        br = new BufferedReader(new FileReader("input.txt"));
//        pw = new PrintWriter("output.txt");
        int n=nextInt();
        String s = nextToken();
        int res = Integer.MAX_VALUE;

        int cnt = 1;
        for(char i = 'A'; i <= 'Z'; i++ ){
            map.put(i, cnt);
            cnt += 1;
        }

        for(int i = 0; i <= n-4; i++){
            res = Math.min(res, check(s, i));
        }
        pw.println(res);
        pw.close();
    }

    private int check(String s, int start) {
        int res = getDist(s.charAt(start), 'A') + getDist(s.charAt(start+1), 'C') + getDist(s.charAt(start+2), 'T') + getDist(s.charAt(start+3), 'G');
        return res;
    }

    private int getDist(char c, char a) {
        int d1 = Math.abs(map.get(c) - map.get(a));
//        int d2 = Math.abs(map.get(a) - map.get('Z')) + Math.abs(map.get(c) - map.get('A'));
        int d3 =  Math.abs(map.get(c) - map.get('Z')) + Math.abs(map.get(a));
        int d2 =  Math.abs(map.get(a) - map.get('Z')) + Math.abs(map.get(c));
        int dist = Math.min(d2,Math.min(d1, d3));

        return dist;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javafx.css.StyleOrigin;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Quan2202
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = in.nextInt();
        String s = in.next();

        int min = 0;
        for (int i = 0; i < s.length() - 3; i++) {
            int a = Math.abs((int) s.charAt(i) - 'A');
            int b = Math.abs((int) s.charAt(i + 1) - 'C');
            int c = Math.abs((int) s.charAt(i + 2) - 'T');
            int d = Math.abs((int) s.charAt(i + 3) - 'G');
            //out.println(a+" "+b+" "+c+" "+d);
            int tmp = Math.min(a, 26 - a) + Math.min(b, 26 - b) + Math.min(c, 26 - c) + Math.min(d, 26 - d);
//            out.println(tmp);
//            out.println("------------------");
            if (i == 0) {
                min = tmp;
            } else if (tmp < min) {
                min = tmp;
            }

        }
        //print the result
        out.print(min);

        out.flush();
    }

    static class InputReader {

        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

import java.util.Scanner;

public class Main {
    public static Scanner scanner = new Scanner(System.in);
    public static Scanner scanner1 = new Scanner(System.in);
    public static int less_operation(int n, String s) {

        int least = Integer.MAX_VALUE;
        for (int i = 0; i < n-3; i++) {
            int operation = 0;
            operation+=Math.min(Math.abs(s.charAt(i)-'A'),'Z'-s.charAt(i)+1);
            operation+=Math.min(Math.abs(s.charAt(i+1)-'C'),'Z'-s.charAt(i+1)+3);
            operation+=Math.min(Math.abs(s.charAt(i+2)-'T'),s.charAt(i+2)-'A' +7);
            operation+=Math.min(Math.abs(s.charAt(i+3)-'G'),'Z'-s.charAt(i+3)+7);

            if (operation < least) least = operation;
        }
        return least;
    }

    public static void main(String[] args) {
        int n = scanner.nextInt();
        scanner.nextLine();
        String s = scanner.nextLine();
        System.out.println(less_operation(n,s));

    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Lalo
 */
public class ContestSandbox {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int length = Integer.parseInt(in.nextLine());
        String s = in.nextLine();
        String genome = "ACTG";
        int miniumChanges = 3215643;
        Map<String, Integer> alphabet = new HashMap<>();

        int a = 1;
        for (char ch = 'A'; ch <= 'Z'; ch++) {
            alphabet.put(String.valueOf(ch), a);
            a++;
        }

        for (int i = 0; (i + 4) <= length; i++) {
            int sum = 0;
            for (int x = 0; x < 4; x++) {
                if (Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1))) <= 13) {
                    sum += Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1)));
                } else if (alphabet.get(s.substring(i + x, i + x + 1)) > alphabet.get(genome.substring(x, x + 1))) {
                    sum += (26 - alphabet.get(s.substring(i + x, i + x + 1)) + alphabet.get(genome.substring(x, x + 1)));
                } else {
                    sum += (26 - alphabet.get(genome.substring(x, x + 1)) + alphabet.get(s.substring(i + x, i + x + 1)));
                }
            }

            if (sum < miniumChanges) {
                miniumChanges = sum;
            }
        }

        System.out.println(miniumChanges);
    }

}

import java.io.*;
import java.util.*;
import java.math.*;
public class name
{
       public static void main(String[]args)throws IOException
       {
              Scanner sc=new Scanner(System.in);
              int n=sc.nextInt();
              String s=sc.next();
              int i,ans=Integer.MAX_VALUE,c=0,k;
              String s1="ACTG";
              for(i=0;i<n-3;i++)
              {
                     int sum=0;
                     for(k=0;k<4;k++)
                     {
                            c=Math.abs((int)(s1.charAt(k))-(int)(s.charAt(i+k)));
                            sum=sum+Math.min(c,26-c);
                     }
                     ans=Math.min(sum,ans);
              }
              System.out.println(ans);

       }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class stringprob
{

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        String s=sc.nextLine();
        int min=Integer.MAX_VALUE;
        for(int j=0;j<n-4+1;j++)
        {
            int res=0;
            int c1=Math.min(Math.abs((int)s.charAt(j)-65),26-Math.abs((int)s.charAt(j)-65));
            int c2=Math.min(Math.abs((int)s.charAt(j+1)-67),26-Math.abs((int)s.charAt(j+1)-67));
            int c3=Math.min(Math.abs((int)s.charAt(j+2)-84),26-Math.abs(((int)s.charAt(j+2)-84)));
            int c4=Math.min(Math.abs((int)s.charAt(j+3)-71),26-Math.abs((int)s.charAt(j+3)-71));
            //System.out.println(c1+" "+c2+" "+c3+" "+c4);
            res=c1+c2+c3+c4;
            if(res<min)
                min=res;
        }
        System.out.println(min);

    }
}

import java.util.*;
import java.io.*;
public class Main{

    public static void main(String args[])
    {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            String s=sc.next();

            int i,j,sum=0,min=Integer.MAX_VALUE;
            for(i=0;i<=n-4;i=i+1)
            {

                    sum=0;

                    sum+=Math.min(Math.abs((s.charAt(i)-'A')),Math.abs(26-Math.abs(s.charAt(i)-'A')));
                     //System.out.println(sum);
                    sum+=Math.min(Math.abs((s.charAt(i+1)-'C')),Math.abs(26-Math.abs(s.charAt(i+1)-'C')));;
                     //System.out.println(sum);
                    sum+=Math.min(Math.abs((s.charAt(i+2)-'T')),Math.abs(26-Math.abs(s.charAt(i+2)-'T')));;
                     //System.out.println(sum);
                    sum+=Math.min(Math.abs((s.charAt(i+3)-'G')),Math.abs(26-Math.abs(s.charAt(i+3)-'G')));;
                    //System.out.println(sum);

                if(sum<min)
                {
                    min=sum;
                }
            }

            System.out.println(min);

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Puneet    //FastRead class is taken from different online Sources
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastInput in = new FastInput(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.ni();

            String str = in.ns();
            char[] s = {'A', 'C', 'T', 'G'};

            int maxans = Integer.MAX_VALUE;

            for (int i = 0; i <= n - 4; i++) {
                int ans = 0;
                for (int j = 0; j < 4; j++) {
                    char a = str.charAt(i + j);
                    char b = s[j];

                    if (a > b) {
                        char c = b;
                        b = a;
                        a = c;
                    }

                    ans += Math.min(b - a, 26 + a - b);
                }
                maxans = Math.min(maxans, ans);
            }

            out.println(maxans);
        }

    }

    static class FastInput {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastInput.SpaceCharFilter filter;

        public FastInput(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String ns() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.lang.Math;

import static java.lang.Math.abs;

public class M {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String b = reader.readLine();
        String[] x = reader.readLine().split("");
        List<String> m = new ArrayList<>();
        m.add("A");
        m.add("C");
        m.add("T");
        m.add("G");

        long min = Integer.MAX_VALUE;
        for (int i = 0; i + 3 < x.length; i++) {
            long res = 0;
            if (!x[i].equals("A")) {

                res += need(x[i], 0);
            }
            if (!x[i + 1].equals("C")) {

                res += need(x[i + 1], 1);
            }
            if (!x[i + 2].equals("T")) {

                res += need(x[i + 2], 2);
            }
            if (!x[i + 3].equals("G")) {
                res += need(x[i + 3], 3);
            }

            if(min>res)min =res;
        }
        System.out.println(min);
    }

    static char[] j = {'A', 'C', 'T', 'G'};

    static int need(String x, int pos) {
        char first = j[pos];
        char second = x.toCharArray()[0];
        int res = abs(first - second);
//        if (second>first){
//            res = Math.min(first+26-second,second-first);
//        }
        return Math.min(res,26-res);
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeMap;
/**
 *
 * @author yijieren
 */
public class Test {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        /*
        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String line2 = scn.nextLine();
        String[] t1 = line1.split(":");
        String[] t2 = line2.split(":");
        scn.close();

        int h1 = Integer.parseInt(t1[0]);
        int m1 = Integer.parseInt(t1[1]);
        int h2 = Integer.parseInt(t2[0]);
        int m2 = Integer.parseInt(t2[1]);
        */

        /*
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String string = scn.nextLine();
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String line = scn.nextLine();
        int n = Integer.parseInt(line);
        String[] arr = new String[n];
        for(int i=0; i<n; i++){
            arr[i] = scn.nextLine();
        }
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String[] tmp = line1.split(" ");

        String line2 = scn.nextLine();
        String[] tmp2 = line2.split(" ");
        scn.close();

        // 输入处理 && 得到数组中的最小值
        int n = Integer.parseInt(tmp[0]);
        int v = Integer.parseInt(tmp[1]);
        int[] nums = new int[n];
        int min = Integer.parseInt(tmp2[0]);
        for(int i=0; i<n; i++){
            nums[i] = Integer.parseInt(tmp2[i]);
            min = Math.min(min, nums[i]);
        }
        */

        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String str = scn.nextLine();
        int n = Integer.parseInt(line1);
        scn.close();

        int counter = 0;
        int result = Integer.MAX_VALUE;
        for(int i=0; i<=n-4; i++){
            counter += Math.min(Math.abs(str.charAt(i) - 'A'), 26-Math.abs(str.charAt(i) - 'A'));
            counter += Math.min(Math.abs(str.charAt(i+1) - 'C'), 26-Math.abs(str.charAt(i+1) - 'C'));
            counter += Math.min(Math.abs(str.charAt(i+2) - 'T'), 26-Math.abs(str.charAt(i+2) - 'T'));
            counter += Math.min(Math.abs(str.charAt(i+3) - 'G'), 26-Math.abs(str.charAt(i+3) - 'G'));

            result = Math.min(counter, result);
            counter = 0;
        }

        System.out.println(result);

    }

}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        char[] template = new char[]{'A', 'C', 'T', 'G'};
        int num_cycle = n - 4 + 1;

        int res = Integer.MAX_VALUE;
        String str = scanner.next();

        for (int i = 0; i < num_cycle; i++) {
            int min_num_op = 0;
            char[] ch = str.substring(i, i + 4).toCharArray();
            for (int k = 0; k < ch.length; k++) {
                int left = Math.abs(template[k] - ch[k]);
                int right = 26 - left;
                min_num_op += Math.min(left, right);
            }
            if (res > min_num_op) res = min_num_op;
        }

        System.out.println(res);
    }
}

//package com.example.programming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class CodeforcesProblems {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        //String[] s = br.readLine().split(" ");
        int n = Integer.parseInt(br.readLine());
        String actg = "ACTG";

        String str = br.readLine();
        int min = 5656;
        for(int i = 0; i<n-3; i++) {
            int te = 0;
            for(int j = 0; j<4; j++) {
                int ch1 = str.charAt(i+j);
                int ch2 = actg.charAt(j);
                int x = Math.min(ch1, ch2);
                int y = Math.max(ch1, ch2);
                int f = y-x;
                int s = x-y+26;
                int diff = Math.min(f,s);
                te += diff;
            }
            if(te<min) min = te;
        }
        System.out.println(min);
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class alpha {
    public static void main(String[] args) throws IOException{
        Reader in=new Reader();
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		String s=in.next();
		char[] c=s.toCharArray();
		int min=Integer.MAX_VALUE;
		for(int i=0;i<=n-4;i++) {
			int cost=0;
			cost+=(Math.min(c[i] - 'A' , 'Z'-c[i] +1));
			cost+=(Math.min(Math.abs(c[i+1] - 'C'),Math.abs('Z'-c[i+1]+3)));
			cost+=Math.min((Math.min(Math.abs(c[i+2] - 'T'),Math.abs('Z'-c[i+2]+20))),Math.abs(c[i+2]-'A'+1+'Z'-'T'));
			cost+=(Math.min(Math.abs(c[i+3] - 'G'),Math.abs('Z'-c[i+3]+7)));
			if(cost<min)
				min=cost;
		}
		w.println(min);
		w.close();
		return;
	}
}

class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public String nextLine() throws IOException{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
        public String next() throws IOException{
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
        }
        public int[] nextIntArray(int n) throws IOException{
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
            }

			return a;
		}
		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
        }
        public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
    }

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {

//        for (int i = 0 ; i < 26 ; i ++) {
//            for (int j = 0 ; j< 26; j++) {
//                System.out.println((char)('A' + i) + " " + (char)('A' + j) + " " + getMin(i, j));
//            }
//        }

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1024 * 1024 * 2);

        int n = Integer.valueOf(br.readLine());
        char a[] = br.readLine().toCharArray();
        int[] v = new int[n];

        for (int i = 0 ; i < n ; i ++) {
            v[i] = a[i] - 'A';
        }

        int b [] = new int[] {'A'-'A','C'-'A', 'T'-'A','G'-'A'};

        int best = Integer.MAX_VALUE;
        for (int i = 0 ; i <= n - 4; i ++) {
            int sum = 0;
            for (int j = 0 ; j < 4 ; j ++) {
                sum += getMin(v[i+j], b[j]);
            }
            best = Math.min(sum, best);
        }
        System.out.println(best);
    }

    private static int getMin(int c1, int c2) {
        int diff1 = Math.abs(c1 - c2);
        int diff2 = 26 - diff1;
        return Math.min(diff1, diff2);
    }

    public static int[] readArrayLine(String line, int n) {
        return readArrayLine(line, n, null, 0);
    }

    private static int[] readArrayLine(String line, int n, int array[], int pos) {
        int[] ret = array == null ? new int[n] : array;
        int start = 0;
        int end = line.indexOf(' ', start);
        for (int i = pos; i < pos + n; i++) {
            if (end > 0)
                ret[i] = Integer.parseInt(line.substring(start, end));
            else
                ret[i] = Integer.parseInt(line.substring(start));
            start = end + 1;
            end = line.indexOf(' ', start);
        }
        return ret;
    }
}

import java.util.Scanner;

/**
 *
 * @author Akhilesh
 */
public class MaximBio1151A {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        scan.nextLine();
        String s = scan.nextLine();

        int temp = s.length() - 3;
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < temp; i++){
            int index = i;
            int count = 0;

            count = Math.min( Math.abs( s.charAt(index) - 'A') , 26 - Math.abs(s.charAt(index) - 'A') );
            index++;

            count += Math.min( Math.abs( s.charAt(index) - 'C') , 26 - Math.abs(s.charAt(index) - 'C') );
            index++;

            count += Math.min( Math.abs( s.charAt(index) - 'T') , 26 - Math.abs(s.charAt(index) - 'T') );
            index++;

            count += Math.min( Math.abs( s.charAt(index) - 'G') , 26 - Math.abs(s.charAt(index) - 'G') );
            min = Math.min(count, min);
        }

        System.out.println(min);
    }
}

import java.util.*;

public class MaximAndBiology {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();

        int best = Integer.MAX_VALUE;
        String g = "ACTG";
        for (int i = 0; i <= n - g.length(); i++) {
            int numOps = 0;
            for (int j = 0; j < g.length(); j++) {
                char curr = s.charAt(i + j);
                char correct = g.charAt(j);
                numOps += Math.min(Math.abs(curr - correct), 26 - Math.abs(curr - correct));
            }
            best = Math.min(best, numOps);

        }

        System.out.println(best);
    }
}

import java.util.Scanner;

public class sos {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		String g=scan.next();
		int min=Integer.MAX_VALUE;
		int dist=0;
		char ar[]= {'A','C','T','G'};
		for(int i=0;i<=n-4;i++)
		{
			dist=0;
//			int cout=0;
			for(int j=i,count=0;count<4;j++,count++)
			{
				int a=Math.abs((ar[count]-'0')-(g.charAt(j)-'0'));
				int b=26-Math.abs((ar[count]-'0')-(g.charAt(j)-'0'));
				dist+=Math.min(a, b);
			}
//			System.out.println(dist);
			min=Math.min(min, dist);

		}
		System.out.println(min);
	}
}

import java.util.*;
import java.io.*;

public class RemString{
	public static void main(String arg[]) throws Exception{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int c=0, j, i, t, max=Integer.MAX_VALUE, n;

    n = Integer.parseInt(br.readLine());
    String str=br.readLine();

        for(i=0 ; i<str.length()-3 ; i++){
                c=0;
                if(str.charAt(i)>65)
                    c+=Math.min(str.charAt(i)-65,91-str.charAt(i));
                    //System.out.print(c+" ");
                if(str.charAt(i+1)>67)
                    c+=Math.min(str.charAt(i+1)-67,91-str.charAt(i+1)+2);
                else
                    c+=Math.min(67-str.charAt(i+1),91-str.charAt(i+1)+2);
                    //System.out.print(c+" ");
                if(str.charAt(i+2)>84)
                    c+=Math.min(str.charAt(i+2)-84,91-str.charAt(i+2)+19);
                else
                    c+=Math.min(84-str.charAt(i+2),str.charAt(i+2)-65+7);
                    //System.out.print(c+" ");
                if(str.charAt(i+3)>71)
                    c+=Math.min(str.charAt(i+3)-71,91-str.charAt(i+3)+6);
                else
                    c+=Math.min(71-str.charAt(i+3),str.charAt(i+3)-65+6);
                    //System.out.print(c+" ");
                max=Math.min(max,c);
                //System.out.print(max+" "+i);
            }
        System.out.print(max);
	}
}

import java.util.*;
import java.io.*;

public class MaximBio{

  public static void main(String arg[]) throws Exception{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int j, i, t, max1=Integer.MAX_VALUE, n, m, k=0, max=0, c;

    n = Integer.parseInt(br.readLine());

    String str = br.readLine();
    String s = "ACTG";

    for(i=0 ; i<n-3 ; i++){

      for(j=0 ; j<4 ; j++){

        char ch = str.charAt(i+j);
        char st = s.charAt(j);
        c = (int)ch;
        m = (int)st;

        k = Math.abs(c-m);
        k = Math.min(k, 26-k);

        max+=k;
        // System.out.print(max+" ");
      }

      max1 = Math.min(max1, max);
      max=0;
    }

    System.out.print(max1);

  }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

//Mann Shah [ DAIICT ].
//fast io

public class Main {
	public static int mod = (int) (1e9 + 7);
	public static long inf = (long) 1e15 + 42;
	static InputReader in;
	static PrintWriter out;

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static void main(String args[]) {

		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		int n = in.nextInt();

		String s = in.readString();
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n-3;i++) {
			int sum =0;
			int x = Math.abs(s.charAt(i)-'A');
			sum += Math.min(x,26-x);
			int y = Math.abs(s.charAt(i+1)-'C');
			sum += Math.min(y,26-y);
			int z = Math.abs(s.charAt(i+2)-'T');
			sum += Math.min(z,26-z);
			int w = Math.abs(s.charAt(i+3)-'G');
			sum += Math.min(w,26-w);

			if(sum < min ) {
				min = sum;
			}
		}

		out.println(min);

		out.close();
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n) {
			long a[] = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextLong();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}

	}

}

// For Pair sorting

// Arrays.sort(arr,new Comparator<Pair>() {
// @Override public int compare(Pair p1, Pair p2)
// {
// return p1.x - p2.x;
// }
// });

// Pair arr[] = new Pair[n];
// arr[0] = new Pair(10, 20);
class Pair {
	int x;
	int y;

	// Constructor
	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

	@Override
	public boolean equals(Object o) {
		Pair p =(Pair)o;
		return (x==p.x && y==p.y);
	}
}

// // Comparator to sort the pair according to first element.
// Arrays.sort(arr, new Comparator<Pair>() {
// @Override public int compare(Pair p1, Pair p2){
//  return p1.x - p2.x;
// }
// });

class couple implements Comparable<couple> {
	int x, y;

	public couple(int m, int f) {
		x = m;
		y = f;
	}

	public int compareTo(couple o) {

		return x - o.x;
	}
}

//package codeforcesa4;
import java.util.*;
public class MaximAndBiology {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        in.nextLine();
        String s=in.nextLine();
        String gen="ACTG";
        int index=0;
        int sum=0;
        int ans=Integer.MAX_VALUE;

        for(int i=0;i<s.length()-3;i++)
        {index=0;
         sum=0;
            for(int j=i;j<i+4;j++)
            {
                int x=s.charAt(j);
                int y=gen.charAt(index);
                int p=Math.abs(x-y);
                int q=26-Math.abs(x-y);
                sum+=Math.min(p, q);

                index++;
            }
            if(sum<ans){
                ans=sum;
            }
        }
        System.out.println(ans);
    }
}

import java.util.*;
public class MyClass {
    public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=1;
	while(t-->0) {
		int l=sc.nextInt();
		String str=sc.next();
		int ans=Integer.MAX_VALUE;
		for(int i=0;i<=str.length()-4;i++) {
			int temp=0;
			temp+=Math.min(Math.abs(str.charAt(i)-'A'), Math.abs('Z'-str.charAt(i)+1));
			if(str.charAt(i+1)>'C') {
				temp+=Math.min(Math.abs(str.charAt(i+1)-'C'), Math.abs('Z'-str.charAt(i+1)+('C'-'A'+1)));
			}else if(str.charAt(i+1)<'C') {
				temp+=Math.min(Math.abs(str.charAt(i+1)-'C'), Math.abs(str.charAt(i+1)-'A'+('Z'-'C'+1)));
			}
			if(str.charAt(i+2)>'T') {
				temp+=Math.min(Math.abs(str.charAt(i+2)-'T'), Math.abs('Z'-str.charAt(i+2)+('T'-'A'+1)));
			}else if(str.charAt(i+2)<'T') {
				temp+=Math.min(Math.abs(str.charAt(i+2)-'T'), Math.abs(str.charAt(i+2)-'A'+('Z'-'T'+1)));
			}
			if(str.charAt(i+3)>'G') {
				temp+=Math.min(Math.abs(str.charAt(i+3)-'G'), Math.abs('Z'-str.charAt(i+3)+('G'-'A'+1)));
			}else if(str.charAt(i+3)<'G') {
				temp+=Math.min(Math.abs(str.charAt(i+3)-'G'), Math.abs(str.charAt(i+3)-'A'+('Z'-'G'+1)));
			}
			ans=Math.min(ans, temp);
		}
		System.out.println(ans);
	}
   }
}

import java.io.*;
import java.util.*;
import java.lang.*;

public class Solution{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        String g="ACTG";
        int min=Integer.MAX_VALUE;
        for(int i=0;i<n-3;i++){
            int sum=0;
            for(int j=0;j<4;j++){
                sum=sum+Math.min(Math.abs((int)s.charAt(i+j)-(int)g.charAt(j)),26-Math.abs((int)s.charAt(i+j)-(int)g.charAt(j)));
            }
            min=Math.min(min,sum);
        }
        System.out.println(min);
    }
}

//codeforces basic code class must be "" public ""

import java.io.*;
import java.util.*;
import java.lang.*;

public class Solution{

    public static void main(String args[]) throws IOException{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    String str=br.readLine();
    String act="ACTG";

    int ans=999999;
    for(int i=0;i<=n-4;i++){
        int temp=0;
        for(int j=0;j<4;j++){
            if(str.charAt(i+j)>act.charAt(j))
            temp+=Math.min(26-str.charAt(i+j)+act.charAt(j),str.charAt(i+j)-act.charAt(j));
            else
            temp+=Math.min(26+str.charAt(i+j)-act.charAt(j),act.charAt(j)-str.charAt(i+j));

        //System.out.println(temp);
        }
        ans=Math.min(ans,temp);
    }

    System.out.println(ans);
    }
}

//package ;
import java.io.*;
import java.util.*;

public class A {
	static char []s;
	static int forw(char start,char end)
	{
		int ans=0;
		while(start!=end)
		{
			if(start=='Z')
				start='A';
			else
				start++;
			ans++;
		}
		return ans;
	}
	static int back(char start,char end)
	{
		int ans=0;
		while(start!=end)
		{
			if(start=='A')
				start='Z';
			else
				start--;
			ans++;
		}
		return ans;
	}
	static int sol2(int i)
	{
		int ans=0;
		char a=s[i];
		char c=s[i+1];
		char t=s[i+2];
		char g=s[i+3];
		ans+=Math.min(forw(a,'A'),back(a,'A'));
		ans+=Math.min(forw(c,'C'),back(c,'C'));
		ans+=Math.min(forw(t,'T'),back(t,'T'));
		ans+=Math.min(forw(g,'G'),back(g,'G'));
		return ans;
	}
	static int sol(int i)
	{
		int res=0;
		int a=s[i]-'A';
		int c=s[i+1]-'A';
		int t=s[i+2]-'A';
		int g=s[i+3]-'A';
//		System.out.println(a+" "+c+" "+t+" "+g);
		res+=Math.min(Math.abs(25-a+1), Math.abs(a-0));
//		System.out.println(res);
		res+=Math.min(Math.abs(25-c+3), Math.abs(c-2));
//		System.out.println(res);
		res+=Math.min(Math.abs(25-t+20), Math.abs(t-19));
//		System.out.println(res);
		res+=Math.min(Math.abs(25-g+7), Math.abs(g-6));
//		System.out.println(res);
		return res;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		s=sc.nextCharArray();
		int ans=Integer.MAX_VALUE;
		for(int i=0;i<n-3;i++)
			ans=Math.min(ans, sol2(i));
		System.out.println(ans);
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}

	import java.io.*;
	import java.util.*;
	public class Solution {
			static int MAX = (int)1e5+1;
			static int ans = Integer.MAX_VALUE;
			static boolean vis[][];
			static int arr[][];
			static ArrayList<String> list = new ArrayList<>();
			public static void main(String[] args)throws Exception{
				//InputReader input = new InputReader(System.in);
				Scanner input = new Scanner(System.in);
				OutputStreamWriter out = new OutputStreamWriter(System.out);
				int n = input.nextInt();
				String target = "ACTG";
				String s = input.next();
				String sub = "";
				char c[] = "abcdefghijklmnopqrstuvwxyz".toUpperCase().toCharArray();
				int res = Integer.MAX_VALUE;
				for(int i =0;i<n;i++) {
					if(i+4<=n)sub = s.substring(i,i+4);
					int count = 0;
					for(int j =0;j<4;j++) {
						char sc= sub.charAt(j);
						char tc = target.charAt(j);
						int count1=0,count2 =0;
						while(true) {
							if(sc == tc)break;
							//System.out.println(sc);
							if(sc == 'Z')sc = 'A';
							else sc++;
							count1++;
						}
						sc = sub.charAt(j);
						tc = target.charAt(j);
						while(true) {
							if(sc == tc)break;
							if(sc =='A')sc = 'Z';
							else sc--;
							count2++;
						}
						count+=Math.min(count1, count2);

					}
					res = Math.min(res, count);
				}
				System.out.println(res);
			}

			public static int gcd(int arr[]) {
				int gcd = 0;
				for(int i =0;i<arr.length;i++) {
					gcd = gcd(arr[i],gcd);
				}
				return gcd;
			}

			public static boolean check(int arr[]) {
				for(int i =0;i<arr.length-1;i++) {
					if(arr[i] != arr[i+1])return false;
				}
				return true;
			}
			public static int sum(int n) {
				int sum =0;
				while(n>0) {
					sum+=(n%10);
					n/=10;
				}
				return sum;
			}
			public static boolean lucky(int n) {
				HashSet<Integer>set = new HashSet<>();
				while(n>0) {
					set.add(n%10);
					n/=10;
				}
				if(set.contains(4) && set.contains(7) && set.size() ==2)return true;
				return false;
			}

			/*
			 3 10 3 5 12
	1 1 1 1
	1 1 1 2
	1 1 1 3
	1 1 1 4
	1 1 1 5
	1 1 1 6
	1 1 1 7
	1 1 1 8
	1 1 1 9
	1 1 1 10
	1 1 2 2
	1 1 2 1
			 */

			public static boolean solve(int x,int y,int tx,int ty) {
				if(x<0 || y<0 || x>=arr.length || y>=arr[0].length || vis[x][y] ||arr[x][y] == -1)return false;
				vis[x][y] = true;
				if(x == tx && y == ty)return true;
				return solve(x-1,y,tx,ty)||
						solve(x+1,y,tx,ty)||
						solve(x,y+1,tx,ty)||
						solve(x,y-1,tx,ty)||
						solve(x-1,y-1,tx,ty)||
						solve(x-1,y+1,tx,ty)||
						solve(x+1,y+1,tx,ty)||
						solve(x+1,y-1,tx,ty);
			}
			public static void construct(int a,int b,int arr[][]) {
				arr[a][b] = -1;
				int x = a,y=b;
				while(x>=0)arr[x--][b] = -1;
				x= a;
				while(x<arr.length)arr[x++][b] = -1;
				y =b;
				while(y<arr[0].length)arr[a][y++] = -1;
				y = b;
				while(y>=0)arr[a][y--] = -1;
				x = a;y=b;
				while(x>=0 && y>=0)arr[x--][y--] = -1;
				x = a;y=b;
				while(x>=0 && y<arr[0].length)arr[x--][y++] = -1;
				x=a;y=b;
				while(x<arr.length && y<arr[0].length)arr[x++][y++] = -1;
				x=a;y=b;
				while(x<arr.length && y>=0)arr[x++][y--] = -1;
			}
			public static int gcd(int a,int b) {
				return b==0? a:gcd(b,a%b);
			}
			public static boolean isPalindrome(int hh,int mm) {
				String s= "";
				if(hh<10)s+="0";
				s+=hh;
				if(mm<10)s+="0";
				s+=mm;
				int l =0;
				int r = s.length()-1;
				while(l<r){
					if(s.charAt(l)!= s.charAt(r))return false;
					l++;
					r--;
				}
				return true;
			}

			public static void sort(int arr[]) {
				ArrayList<Integer>list = new ArrayList<>();
				for(int it:arr)list.add(it);
				Collections.sort(list);
				for(int i =0;i<arr.length;i++)arr[i] = list.get(i);
			}
			public static void swap(int a,int b,int arr[]){
				int t = arr[a];
				arr[a]= arr[b];
				arr[b] = t;
			}

	}
	class Pair{
		int x,y;
		public Pair(int x,int y) {
			this.x = x;
			this.y = y;
		}
	}
	class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, readInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E') {
						return res * Math.pow(10, readInt());
					}
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			if (filter != null) {
				return filter.isSpaceChar(c);
			}
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

import java.io.*;
import java.util.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static final double EPS = 1e-9;
	static int mod = 1000000007;
	static int inf = (int) 1e9 + 2;
	static long[] fac;
	static int[] si;
	static ArrayList<Integer> primes;
	static ArrayList<Integer>[] ad;
	static int[] ans;
	static int m, k;
	static HashMap<Integer, Integer> t;
	static boolean f;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n=sc.nextInt();
		int ans=Integer.MAX_VALUE;
		char[]a=sc.nextLine().toCharArray();
		char []b= {'A','C','T','G'};
		for(int i=0;i<n;i++) {
			if(i+3>=n)
				break;
			int tmp=0;
			tmp+=Math.min(a[i]-'A',Math.abs('Z'-a[i]+1));
			if(a[i+1]>='C')
				tmp+=Math.min(a[i+1]-'C',Math.abs('Z'-a[i+1]+1-'A'+'C'));
			else
				tmp+=Math.min('C'-a[i+1],'Z'-'C'+a[i+1]-'A'+1);
			if(a[i+2]>='T')
				tmp+=Math.min(a[i+2]-'T',Math.abs('Z'-a[i+2]+1-'A'+'T'));
			else
				tmp+=Math.min('T'-a[i+2],'Z'-'T'+a[i+2]-'A'+1);
			if(a[i+3]>='G')
				tmp+=Math.min(a[i+3]-'G',Math.abs('Z'-a[i+3]+1-'A'+'G'));
			else
				tmp+=Math.min('G'-a[i+3],'Z'-'G'+a[i+3]-'A'+1);
		//	System.out.println(Math.min(a[i]-'A',Math.abs('Z'-a[i]+1)));
			//System.out.println(Math.min(a[i+1]-'C',Math.abs('Z'-a[i+1]+1+'A'-'C')));
		//	System.out.println(Math.min(a[i+2]-'T',Math.abs('Z'-a[i+2]+1+'A'-'T')));
			//System.out.println(Math.min(a[i+3]-'G',Math.abs('Z'-a[i+3]+1+'A'-'G')));
			ans=Math.min(ans, tmp);
		}
		out.println(ans);
		out.close();
	}

	static class seg implements Comparable<seg> {
		int s;
		int e;
		int num;
		int id;

		seg(int s, int e) {
			this.s = s;
			this.e = e;
		}

		public String toString() {
			return s + " " + e + " " + num + " " + id;
		}

		@Override
		public int compareTo(seg o) {
			if (o.s == s)
				return o.e - e;
			return s - o.s;
		}
	}

	static public class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy, candies;

		SegmentTree(int[] in) {
			array = in.clone();
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			candies = new int[N << 1];
			build(1, 1, N);
			build2(1, 1, N);
		}

		public String toString() {
			return Arrays.toString(sTree) + "\n" + Arrays.toString(candies);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = (sTree[node << 1] + sTree[node << 1 | 1]) % 10;
				if (sTree[node << 1] + sTree[node << 1 | 1] >= 10)
					candies[node]++;
			}
		}

		void build2(int node, int b, int e) // O(n)
		{
			if (b == e)
				b = e;
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				candies[node] = (candies[node << 1] + candies[node << 1 | 1]);
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		// static int c=0;
		int query(int i, int j) {
			// c=0;
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return candies[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;
		}
	}

	static int x, y, d;

	static long power(int i) {
		// if(i==0)
		// return 1;
		long a = 1;
		for (int k = 0; k < i; k++)
			a *= i;
		return a;
	}

	static void extendedEuclid(int a, int b) {
		if (b == 0) {
			x = 1;
			y = 0;
			d = a;
			return;
		}
		extendedEuclid(b, a % b);
		int x1 = y;
		int y1 = x - a / b * y;
		x = x1;
		y = y1;
	}

	static void dfs(int u) {
		int counter = 1;
		for (int v : ad[u])
			if (ans[v] == 0) {
				if (counter == ans[u]) {
					counter++;
					ans[v] = counter;
				} else
					ans[v] = counter++;
				if (counter > k)
					f = false;
				dfs(v);
			}
	}

	static void bfs(int s) {
		Queue<Integer> q = new LinkedList();
		q.add(s);
		ans[s] = 1;
		while (!q.isEmpty()) {
			int u = q.remove();
			int c = 1;
			for (int v : ad[u]) {
				if (ans[v] == 0) {
					// System.out.println(u);
					if (c == ans[u]) {
						c++;
						ans[v] = c++;
					} else
						ans[v] = c++;
					// System.out.println(v+" "+c);
					if (ans[v] > k)
						f = false;
					q.add(v);
				}
			}
		}
	}

	static void seive() {
		si = new int[1000001];
		primes = new ArrayList<>();
		int N = 1000001;
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);

		}
	}

	static long inver(long x) {
		int a = (int) x;
		long e = (mod - 2);
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				// System.out.println(res*a);
				res = (int) ((1l * res * a) % mod);
			}
			a = (int) ((1l * a * a) % mod);
			e >>= 1;
		}
		// out.println(res+" "+x);
		return res % mod;
	}

	static long fac(int n) {
		if (n == 0)
			return fac[n] = 1;
		if (n == 1)
			return fac[n] = 1;
		long ans = 1;
		for (int i = 1; i <= n; i++)
			fac[i] = ans = (i % mod * ans % mod) % mod;
		return ans % mod;
	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class unionfind {
		int[] p;
		int[] size;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t,i,j=0,n,m,k=0,l,p,h,r;
		String s,st;
		n=in.nextInt();
		s=in.next();
		char c2,c1;
		char c[]=s.toCharArray();
		char ch[]={'A','C','T','G'};
		int a[]=new int[n-3];
		for(i=0;i<n-3;i++)
		{
		     p=0;
		     for(j=0;j<4;j++)
		     {
		         m=0;k=0;
		         c2=c[i+j];
		         c1=c[i+j];
    		     while(c2!=ch[j])
    		     {
    		         m++;
    		         if(c2=='A')
    		             c2='Z';
    		         else
    		         {
    		             r=(int)c2;
    		             c2=(char)(r-1);
    		         }
    		     }
    		     while(c1!=ch[j])
    		     {
    		         k++;
    		         if(c1=='Z')
    		             c1='A';
    		         else
    		         {
    		             r=(int)c1;
    		             c1=(char)(r+1);
    		         }
    		     }
    		     p+=Math.min(k,m);
		     }
		     a[i]=p;
		}
		Arrays.sort(a);
		System.out.println(a[0]);
	}
}

import java.io.PrintWriter;
import java.util.Scanner;

public class MaximandBiology {

	void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt();
		String s = in.next();

		int min = Integer.MAX_VALUE;
		// ACTG
		for (int i = 0; i <= n - 4; i++) {

			char[] a = s.substring(i, i + 4).toCharArray();

			int v = Math.min(Math.min(Math.abs(a[0] - 'A'), Math.abs('Z' - a[0] + 1)),
					Math.abs(a[0] - 'A' + 'Z' - 'A' + 1));
			v += Math.min(Math.min(Math.abs(a[1] - 'C'), Math.abs('Z' - a[1] + 'C' - 'A' + 1)),
					Math.abs(a[1] - 'A' + 'Z' - 'C' + 1));
			v += Math.min(Math.min(Math.abs(a[2] - 'T'), Math.abs('Z' - a[2] + 'T' - 'A' + 1)),
					Math.abs(a[2] - 'A' + 'Z' - 'T' + 1));
			v += Math.min(Math.min(Math.abs(a[3] - 'G'), Math.abs('Z' - a[3] + 'G' - 'A' + 1)),
					Math.abs(a[3] - 'A' + 'Z' - 'G' + 1));
			min = Math.min(min, v);

		}
		out.println(min);

	}

	void run() {
		try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);) {
			solve(in, out);
		}
	}

	public static void main(String args[]) {
		new MaximandBiology().run();
	}

}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Solution {

	public static void main(String args[]) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[] s = { 'A', 'C', 'T', 'G' };
		int[][] dis = new int[26][4];
		for (int i = 65; i <= 90; i++) {
			char ch = (char) i;
			for (int j = 0; j < 4; j++) {
				int d = Math.abs(ch - s[j]);
				if (ch == 'Z') {
					d = Math.min(d, Math.abs('A' - s[j]) + 1);
				} else if (ch == 'A') {
					d = Math.min(d, Math.abs('Z' - s[j]) + 1);
				} else {
					d = Math.min(d, Math.abs('Z' - s[j]) + (ch - 'A') + 1);
					d = Math.min(d, Math.abs('A' - s[j]) + ('Z' - ch) + 1);
				}
				dis[i - 65][j] = d;
			}
		}
		//System.out.println(Arrays.deepToString(dis));
		String s1 = br.readLine();
		char[] a = s1.toCharArray();
		long max = Integer.MAX_VALUE;
		for (int i = 0; i <= n - 4; i++) {
			int x = 0;
			int k = 0;
			for (int j = i; j < i + 4 && j < n; j++) {
				char ch = a[j];
				int d = dis[ch-65][k];
				x = x + d;
				k++;
			}
			max = Math.min(max, x);
		}
		System.out.println(max);

	}

}

import java.util.*;
public class A{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        char[] c=s.toCharArray();
        int min=100000000,sum=0;
        int diff=0;
        for(int i=0;i<n-3;i++){
            sum=0;
            diff=Math.abs(s.charAt(i)-'A');
            //System.out.println('A'-'C');
            //System.out.println('A'-'T');
            //System.out.println('A'-'G');
            //System.out.println('A'-'A');
            if(diff>12)
            {
                sum+=Math.abs(26-diff);
                //System.out.println(26-diff);
                //System.out.println(Math.abs(s.charAt(i)-'Z'-('A'-64)));
            }
            else{
                sum+=diff;
            }
            diff=Math.abs(s.charAt(i+1)-'C');
            if(diff>12)
            {
                sum+=Math.abs(26-diff);
                //System.out.println(diff);
            }
            else{
                //System.out.println(diff);
                sum+=diff;
            }
            diff=Math.abs(s.charAt(i+2)-'T');
            if(diff>12)
            {
                sum+=Math.abs(26-diff);
            }
            else{
                sum+=diff;
            }
            diff=Math.abs(s.charAt(i+3)-'G');
            if(diff>12)
            {
                //System.out.println(diff);
                sum+=Math.abs(26-diff);
            }
            else{
               // System.out.println(diff);
                sum+=diff;
            }
            //System.out.println(sum);
            if(sum<min)
                min=sum;
        }
        System.out.println(min);
    }
}

// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.*;

public class Main
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
         FastReader sc=new FastReader();
         int n=sc.nextInt();
         String s=sc.next();
         StringBuilder sb=new StringBuilder(s);
         int i;
         int min=Integer.MAX_VALUE;
         int sol=0;
         for(i=0;i<(n-3);i++)
         {
             int diff1,diff2;
             diff1=Math.abs(sb.charAt(i)-'A');
             diff2=Math.abs(26-diff1);
             sol=sol+Math.min(diff2,diff1);

             diff1=Math.abs(sb.charAt(i+1)-'C');
             diff2=Math.abs(26-diff1);
             sol=sol+Math.min(diff2,diff1);

             diff1=Math.abs(s.charAt(i+2)-'T');
             diff2=Math.abs(26-diff1);
             sol=sol+Math.min(diff2,diff1);

             diff1=Math.abs(sb.charAt(i+3)-'G');
             diff2=Math.abs(26-diff1);
             sol=sol+Math.min(diff2,diff1);
             if(sol<min)
             min=sol;
             sol=0;
         }
         System.out.println(min);
    }
}

import java.util.*;
public class file{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
scan.nextLine();
String str=scan.nextLine();
int min=Integer.MAX_VALUE;
for(int i=0;i<=str.length()-4;i++){
int sum=0;
int dif=0,diff=0;

int ch1=str.charAt(i);
 dif=Math.abs(ch1-'A');
 diff=26-dif;
sum+=(dif>diff?diff:dif);

int ch2=str.charAt(i+1);
 dif=Math.abs(ch2-'C');
 diff=26-dif;
sum+=(dif>diff?diff:dif);

int ch3=str.charAt(i+2);
dif=Math.abs(ch3-'T');
 diff=26-dif;
sum+=(dif>diff?diff:dif);

int ch4=str.charAt(i+3);
 dif=Math.abs(ch4-'G');
 diff=26-dif;
sum+=(dif>diff?diff:dif);

if(min >sum && sum>=0){
min=sum;
}
}
System.out.println(min);
}
}

import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }

    static void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int [n1];
        int R[] = new int [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2){
            if (L[i] <= R[j]){
                arr[k] = L[i];
                i++;
            }
            else{
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1){
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    static void sort(int arr[], int l, int r) {
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static void mergel(long arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        long L[] = new long [n1];
        long R[] = new long [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2){
            if (L[i] <= R[j]){
                arr[k] = L[i];
                i++;
            }
            else{
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1){
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    static void sortl(long arr[], int l, int r) {
        if (l < r)
        {
            int m = (l+r)/2;
            sortl(arr, l, m);
            sortl(arr , m+1, r);
            mergel(arr, l, m, r);
        }
    }

    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n=in.nextInt();
        String str=in.next();
        int min=10000000;
        for(int i=0;i<n-3;i++){
            int cost=0;
            char arr[]=str.substring(i,i+4).toCharArray();
            cost+=Math.min(Math.abs(arr[0]-'A'),Math.abs(26-(arr[0]-'A')));
            cost+=Math.min(Math.abs(arr[1]-'C'),Math.abs(26-Math.abs(arr[1]-'C')));
            cost+=Math.min(Math.abs(arr[2]-'T'),Math.abs(26-Math.abs(arr[2]-'T')));
            cost+=Math.min(Math.abs(arr[3]-'G'),Math.abs(26-Math.abs(arr[3]-'G')));
            min=Math.min(cost,min);
        }
        out.println(min);

        out.close();
    }
}

//DIII
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        FastReader in = new FastReader();
        OutputWriter out = new OutputWriter();
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(FastReader in, OutputWriter out) {
            int n = in.nextInt();
            String g = in.nextLine();
            int cost = (int) 1e9;
            for (int i = 0; i + 3 < n; i++) {
                int costA = Math.abs(g.charAt(i) - 'A');
                costA = Math.min(costA, 26 - costA);
                int costB = Math.abs(g.charAt(i + 1) - 'C');
                costB = Math.min(costB, 26 - costB);
                int costC = Math.abs(g.charAt(i + 2) - 'T');
                costC = Math.min(costC, 26 - costC);
                int costD = Math.abs(g.charAt(i + 3) - 'G');
                costD = Math.min(costD, 26 - costD);

                cost = Math.min(cost, costA + costB + costC + costD);
            }
            out.printLine(cost);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in),32768);
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter() {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }
}

import java.util.Hashtable;
import java.util.Scanner;

public class CF1151D2A {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		Hashtable<Character, Integer> map = new Hashtable<>();
		map.put('A',1);
		map.put('B',2);
		map.put('C',3);
		map.put('D',4);
		map.put('E',5);
		map.put('F',6);
		map.put('G',7);
		map.put('H',8);
		map.put('I',9);
		map.put('J',10);
		map.put('K',11);
		map.put('L',12);
		map.put('M',13);
		map.put('N',14);
		map.put('O',15);
		map.put('P',16);
		map.put('Q',17);
		map.put('R',18);
		map.put('S',19);
		map.put('T',20);
		map.put('U',21);
		map.put('V',22);
		map.put('W',23);
		map.put('X',24);
		map.put('Y',25);
		map.put('Z',26);
		int n = s.nextInt();
		s.nextLine();
		String v = s.nextLine();
		String obj = "AHTC";
		int[] obji = {1,3,20,7};
		int min=99999999;
		for (int i = 0; i <= v.length()-4; i++) {
			int m = 0;
			for (int j = 0; j < 4; j++) {
				char vj = v.charAt(j+i);
				int x =map.get(vj);
				int y = obji[j];
				if(Math.abs(map.get(vj)-obji[j])>13) {
					m+=26-Math.abs(map.get(vj)-obji[j]);
				}else {
					m+=Math.abs(map.get(vj)-obji[j]);
				}
			}
			if(m<min) {
				min=m;
			}
		}
		System.out.println(min);
	}

}

// Change Of Plans BABY.... Change Of Plans //
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class maximAndBiology {

    static void MainSolution() {
        n=ni();
        char ch[]=ns().toCharArray();int min=Integer.MAX_VALUE;
        for(int i=0;i<n-3;i++) {
            int temp = 0;
            temp+=minVal(ch[i]-'A');
            temp+=minVal(ch[i+1]-'C');
            temp+=minVal(ch[i+2]-'T');
            temp+=minVal(ch[i+3]-'G');
            min=min(min,temp);
        }
        pl(min);
    }
    static int minVal(int x){
        x=abs(x);
        return min(x,26-x);
    }

    /*----------------------------------------------------------------------------------------------------------------*/
    //THE DON'T CARE ZONE BEGINS HERE...\\
    static int mod9 = 1000000007;
    static int n, m, l, k, t;
    static AwesomeInput input = new AwesomeInput(System.in);
    static PrintWriter pw = new PrintWriter(System.out, true);

    // The Awesome Input Code is a fast IO method using Input Stream but with certain manipulations by me //
    static class AwesomeInput {
        private InputStream letsDoIT;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        private AwesomeInput(InputStream incoming) {
            this.letsDoIT = incoming;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = letsDoIT.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private long ForLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        private String ForString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);
        }
    }

    // functions to take input//
    static int ni() {
        return (int) input.ForLong();
    }

    static String ns() {
        return input.ForString();
    }

    static long nl() {
        return input.ForLong();
    }

    static double nd() throws IOException {
        return Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine());
    }

    //functions to give output
    static void pl() {
        pw.println();
    }

    static void p(Object o) {
        pw.print(o + " ");
    }

    static void pws(Object o) {
        pw.print(o + "");
    }

    static void pl(Object o) {
        pw.println(o);
    }

    // Fast Sort is Radix Sort
    public static int[] fastSort(int[] f) {
        int n = f.length;
        int[] to = new int[n];
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < n; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < n; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }

    public static void main(String[] args) {      //threading has been used to increase the stack size.

        new Thread(null, null, "Vengeance", 1 << 25)  //the last parameter is stack size desired.
        {
            public void run() {
                try {
                    double s = System.currentTimeMillis();
                    MainSolution();
                    //pl(("\nExecution Time : " + ((double) System.currentTimeMillis() - s) / 1000) + " s");
                    pw.flush();
                    pw.close();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
}

import java.util.*;
import java.lang.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.io.*;
public class Solution {
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try{
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
	public int[] readIntArray(int n) {
			int[] arr = new int[n];
			for(int i=0; i<n; ++i)
				arr[i]=nextInt();
			return arr;
		}

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
	static int solve(String str, int n) {
		String samp = "ACTG";
		int min = Integer.MAX_VALUE;
		int i = 0;
		int j = 3;
		int total = 0;
			while(j < n) {
				total = 0;
				int l = 0;
				for(int k=i;k<=j;k++) {
					int x = Math.abs(samp.charAt(l) - str.charAt(k));
						total += Math.min(Math.abs(x), Math.abs((90 - Math.max(samp.charAt(l), str.charAt(k)) + Math.min(
								samp.charAt(l), str.charAt(k)) - 64)));
						l++;
				}
				if(total < min) {
					min = total;
				}
				j++;
				i++;
			}
		return min;
	}
	public static void main(String args[]) {
        FastReader sc = new FastReader();
        long start = System.currentTimeMillis();
        	int n = sc.nextInt();
        	String str = sc.next();

        	System.out.println(solve(str,n));
        	long end = System.currentTimeMillis();
        	NumberFormat formatter = new DecimalFormat("#0.00000");
        	//System.out.print("Execution time is " + formatter.format((end - start) / 1000d) + " seconds");
        }
}

import java.util.*;

public class Thing{
   public static void main(String[] args){
      char[] arrTwo = {'A', 'C', 'T', 'G'};
      Scanner input = new Scanner(System.in);
      int a = input.nextInt();
      String s = input.next();
      char[] arr = new char[a];
      for(int i = 0; i < a; i++){
         arr[i] = s.charAt(i);
      }
      List<Integer> ls = new ArrayList<Integer>();
      for(int i = 0; i < a - 3; i++){
         int sum = 0;
         int p = 0;
         for(int j = i; j < i + 4; j++){
            if(Math.abs(arr[j] - arrTwo[p]) > 13){
               sum += (26 - Math.abs(arr[j] - arrTwo[p]));
               p++;
            }else{
               sum += Math.abs(arr[j] - arrTwo[p]);
               p++;
            }
         }
         ls.add(sum);
      }
      int z = Integer.MAX_VALUE;
      for(int i = 0; i < ls.size(); i++){
         if(ls.get(i) < z){
            z = ls.get(i);
         }
      }
      System.out.println(z);
   }
}

import java.io.*;

public class Main1151A
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = Integer.parseInt(br.readLine());
        char[] arr = br.readLine().toCharArray();
        int min = Integer.MAX_VALUE;
        char[] actg = {'A','C','T','G'};
        for(int i=0;i<arr.length-3;++i)
        {
            int ans = 0;
            for(int j=0;j<4;++j)
            {
                int lo = Math.min(actg[j],arr[i+j]);
                int hi = Math.max(actg[j],arr[i+j]);
                ans+= Math.min(hi-lo,26+lo-hi);
            }
            min = Math.min(min,ans);
        }
        bw.write(min+"");
        bw.close();
    }

}

import java.util.Scanner;

public class Genom {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		String str= sc.next();
		String gnome= "ACTG";
		int	ans= 1000;

		for(int i=0;i<n-3;i++) {

			int a=0;
			for(int j=0; j< 4;j++) {

				int x = Math.abs(str.charAt(i+j)-gnome.charAt(j));
				a+=Math.min(x, 26-x);
			}
			ans= Math.min(ans, a);
		}

		System.out.println(ans);
		sc.close();
	}

}

import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        String genom="ACTG";
        int len=s.length();
        int result=Integer.MAX_VALUE;
        for (int i=0;i<len-3;i++)
        {
            int curr=0;
            for (int j=0;j<4;j++)
            {
                int t=Math.abs(genom.charAt(j)-s.charAt(i+j));
                if (t>13)
                    t=26%t;
                curr+=t;
            }
            result=Math.min(curr,result);
        }
        System.out.println(result);
    }
}

// https://codeforces.com/problemset/problem/1151/A

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner read = new Scanner(System.in);

		int n = Integer.parseInt( read.nextLine() );
		String s = read.nextLine();

		int minOperationCount = Integer.MAX_VALUE;
		for (int i = 0; i <= n-4; ++i) {
			String substring = s.substring(i, i+4);

			char substringFirstChar = substring.charAt(0);
			char substringSecondChar = substring.charAt(1);
			char substringThirdChar = substring.charAt(2);
			char substringFourthChar = substring.charAt(3);

			int backwardDistanceToA = Math.abs( substringFirstChar - 'A' );
			int forwardDistanceToA = Math.abs( 26 - backwardDistanceToA );

			int backwardDistanceToC = Math.abs( substringSecondChar - 'C' );
			int forwardDistanceToC = Math.abs( 26 - backwardDistanceToC );

			int backwardDistanceToT = Math.abs( substringThirdChar - 'T' );
			int forwardDistanceToT = Math.abs( 26 - backwardDistanceToT );

			int backwardDistanceToG = Math.abs( substringFourthChar - 'G' );
			int forwardDistanceToG = Math.abs( 26 - backwardDistanceToG );

			int operationCount =
				Math.min(forwardDistanceToA, backwardDistanceToA) +
				Math.min(forwardDistanceToC, backwardDistanceToC) +
				Math.min(forwardDistanceToT, backwardDistanceToT) +
				Math.min(forwardDistanceToG, backwardDistanceToG);

			minOperationCount = Math.min(minOperationCount, operationCount);
		}

		System.out.println(minOperationCount);

		// Close scanner
		read.close();
	}

}

import java.io.*;
import java.util.*;

public class Main {
  static Scanner in = new Scanner(System.in);
  static PrintWriter out = new PrintWriter(System.out);

  public static void main(String[] args) {
    int n = in.nextInt();
    in.nextLine();
    String dna = in.nextLine();

    int[] dnaNumber = new int[n];
    for (int i = 0; i < n; i++) {
      dnaNumber[i] = dna.charAt(i) - 'A';
    }

    int A = 'A' - 'A';
    int C = 'C' - 'A';
    int T = 'T' - 'A';
    int G = 'G' - 'A';
    int minOperations = 10000000;
    for (int i = 0; i < n - 3; i++) {
      int distA = Math.abs(dnaNumber[i] - A);
      int distC = Math.abs(dnaNumber[i + 1] - C);
      int distT = Math.abs(dnaNumber[i + 2] - T);
      int distG = Math.abs(dnaNumber[i + 3] - G);
      int minA = Math.min(distA, (26 - distA));
      int minC = Math.min(distC, (26 - distC));
      int minT = Math.min(distT, (26 - distT));
      int minG = Math.min(distG, (26 - distG));
      // out.println("T: " + (26 - (T - dnaNumber[i + 2])));
      // out.println("i: " + i);
      // out.println("abcd: " + dnaNumber[i] + "," + dnaNumber[i + 1] + "," + dnaNumber[i + 2] + "," + dnaNumber[i + 3]);
      // out.println("min A: " + minA);
      // out.println("min C: " + minC);
      // out.println("min T: " + minT);
      // out.println("min G: " + minG);
      minOperations = Math.min(minA + minC + minT + minG, minOperations);
    }

    out.println(minOperations);

    in.close();
    out.close();
  }
}

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Sirius {
    public static void main(String[] args) throws IOException {
       Scanner scan = new Scanner(System.in);
       int n = scan.nextInt();
       scan.nextLine();
       char[] b = scan.nextLine().toCharArray();
       int min = Integer.MAX_VALUE;
       for(int i= 0; i+3 < b.length; ++i){
           int counter = 0;
           if(b[i] != 'A'){
               counter += Math.min(Math.abs((int)'A' - (int)b[i]), 26 - Math.abs((int)'A' - (int)b[i]));
           }
           if(b[i+1] != 'C'){
               counter += Math.min(Math.abs((int)'C' - (int)b[i+1]), 26 - Math.abs((int)'C' - (int)b[i+1]));
           }
           if(b[i+2] != 'T'){
               counter += Math.min(Math.abs((int)'T' - (int)b[i+2]),26 - Math.abs((int)'T' - (int)b[i+2]));
           }
           if(b[i+3] != 'G'){
               counter += Math.min(Math.abs((int)'G' - (int)b[i+3]),26 - Math.abs((int)'G' - (int)b[i+3]));
           }
           min = Math.min(counter, min);
       }
        System.out.println(min);
    }
}

import java.io.*;
import java.util.*;

public class A {
	// ------------------------

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		// ------------------------
		String bs=sc.nextLine();
		char[]s=sc.nextLine().toCharArray();
		int[]ans=new int[s.length];
		for(int i=0;i<s.length;i++){
			int c=(int)(s[i]-'A');
			ans[i]+=dist(c,0);
			if(i>0)
				ans[i-1]+=dist(c,2);
			if(i>1)
				ans[i-2]+=dist(c,19);
			if(i>2)
				ans[i-3]+=dist(c,6);
		}
		int min=Integer.MAX_VALUE;
		for(int i=0;i+3<s.length;i++)
			min=Math.min(min,ans[i]);
		System.out.println(min);
		// ------------------------
		out.close();
	}
	//------------------------
	private static int dist(int a,int b){
		int d1=a-b;
		while(d1<0)
			d1+=26;
		int d2=b-a;
		while(d2<0)
			d2+=26;
		return Math.min(d1, d2);
	}
	public static PrintWriter out;
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
	static String s;
    public static void main(String args[] ) throws Exception {
    	Scanner sc = new Scanner(System.in);
    	int n=sc.nextInt();
    	s=sc.nextLine();
    	s=sc.nextLine();
    	int ans =1000000000;
    	for(int i=0;i<=n-4;i++) {
    		ans=Math.min(opertaions(i), ans);
    	}
    System.out.println(ans);
    }

    static int opertaions(int start) {
    	String my="ACTG";
		int ans =0;
    	for(int i=0;i<4;i++) {

    		if(my.charAt(i)<='A'+13) {
    			if(s.charAt(start+i)>my.charAt(i)&&s.charAt(start+i)<my.charAt(i)+13) {
    				ans+= s.charAt(start+i)-my.charAt(i);
    			}else {
    				if(s.charAt(start+i)>='A'&&s.charAt(start+i)<=my.charAt(i)) {
    					ans += my.charAt(i)-s.charAt(start+i);
    				}else {
    					ans += (my.charAt(i)-'A'+'Z'-s.charAt(start+i)+1);
    				}
    			}
    		}else {
    			if(s.charAt(start+i)<my.charAt(i)&&s.charAt(start+i)>my.charAt(i)-13) {
    				ans +=my.charAt(i)- s.charAt(start+i);
    			}else {
    				if(s.charAt(start+i)>='A'&&s.charAt(start+i)<=my.charAt(i)-13) {
    					ans += (s.charAt(start+i)-'A'+'Z'-my.charAt(i)+1);
    				}else {
    					ans += s.charAt(start+i)-my.charAt(i);
    				}
    			}

    		}

    	}

    	return ans;

    }
}

//package CodeForces.C553;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class A {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int len = in.nextInt();
            final String s = in.next();
            final String com = "ACTG";
            int ans = Integer.MAX_VALUE;
            for (int i=0;i<s.length()-3;i++) {
                int temp = 0;
                for (int j=0;j<4;j++) {
                    int diff = Math.abs(s.charAt(i+j) - com.charAt(j));
                    int val = Integer.min(diff, 26-diff);
                    temp+=val;
                }
                ans = Integer.min(ans, temp);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sandip Jana
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char s[] = in.next().toCharArray();
            int ans = 999999;
            for (int i = 0; i < s.length - 3; i++) {
                int res = ok(s[i], 'A') + ok(s[i + 1], 'C') + ok(s[i + 2], 'T') + ok(s[i + 3], 'G');
                ans = Math.min(ans, res);
            }
            out.println(ans);
        }

        int ok(char a, char b) {
            if (a <= b)
                return Math.min(b - a, 26 - b + a);
            else
                return Math.min(a - b, 26 - a + b);
        }

    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int len = sc.nextInt();
		int max = Integer.MAX_VALUE;
		sc.nextLine();
		String s = sc.nextLine();
		for(int i = 0; i<=s.length() - 4; i++){
		    int cnt = 0;
		    cnt += Math.min(26 - Math.abs(s.charAt(i) - 'A'), Math.abs(s.charAt(i) - 'A'));
		    cnt += Math.min(26 - Math.abs(s.charAt(i + 1) - 'C'), Math.abs(s.charAt(i + 1) - 'C'));
		    cnt += Math.min(26 - Math.abs(s.charAt(i + 2) - 'T'), Math.abs(s.charAt(i + 2) - 'T'));
		    cnt += Math.min(26 - Math.abs(s.charAt(i + 3) - 'G'), Math.abs(s.charAt(i + 3) - 'G'));
		    max = Math.min(max, cnt);
		}
		out.println(max);
		out.flush();
	}
}

import java.util.*;
import java.io.*;
import java.math.*;
public class A553{

	public static void main(String args[]){
		FastReader sc = new FastReader();
		StringBuilder sb=new StringBuilder();
		int t,i,n,j,x;
		t=1;
		while(t-->0){
            n=sc.nextInt();
            char s[]=sc.next().toCharArray();
            char p[]={'A','C','T','G'};
            int min=Integer.MAX_VALUE;
            int count;
            for(i=0;i<=n-4;i++){
                count=0;
                x=0;
                for(j=i;j<=i+3;j++,x++){
					if(s[j]==p[x])
						continue;
					else{
						int diff1='Z'-p[x]+(s[j]-'A'+1);
						int diff3='Z'-s[j]+(p[x]-'A'+1);
						int diff2=Math.abs(s[j]-p[x]);
						//out.println(i+" "+diff1+" "+diff2);
						count+=Math.min(diff1,Math.min(diff3,diff2));
					}
				}
				//out.println(count);
                min=Math.min(min,count);
            }
            sb.append(min).append('\n');
		}
		sb.deleteCharAt(sb.length()-1);
		out.println(sb);
	}

	static PrintWriter out;
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out,true);
		}
		String next(){
			while(st==null || !st.hasMoreElements()){
				try{
					st= new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str = "";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}

	public static boolean isPrime(int n) {
		if(n<2) return false;
		for(int i=2;i<=(int)Math.sqrt(n);i++) {
			if(n%i==0) return false;
		}
		return true;
	}

	public static void print(int a[],int l,int r){
		int i;
		for(i=l;i<=r;i++)
			out.print(a[i]+" ");
		out.println();
	}

	public static long fastexpo(long x, long y, long p){
		long res=1;
		while(y > 0){
			if((y & 1)==1)
				res= ((res%p)*(x%p))%p;
			y= y >> 1;
			x = ((x%p)*(x%p))%p;
		}
		return res;
	}

	public static boolean[] sieve (int n) {
		boolean primes[]=new boolean[n+1];
		Arrays.fill(primes,true);
		primes[0]=primes[1]=false;
		for(int i=2;i*i<=n;i++){
			if(primes[i]){
				for(int j=i*i;j<=n;j+=i)
					primes[j]=false;
			}
		}
		return primes;
	}

	public static long gcd(long a,long b){
        return (BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))).longValue();
    }

    public static void merge(long a[],int l,int m,int r){
        int n1,n2,i,j,k;
        n1=m-l+1;
        n2=r-m;

        long L[]=new long[n1];
        long R[]=new long[n2];

        for(i=0;i<n1;i++)
            L[i]=a[l+i];
        for(j=0;j<n2;j++)
            R[j]=a[m+1+j];

        i=0;j=0;

        k=l;
        while(i<n1&&j<n2){
            if(L[i]<=R[j]){
                a[k]=L[i];
                i++;
            }
            else{
                a[k]=R[j];
                j++;
            }
            k++;
        }

        while(i<n1){
            a[k]=L[i];
            i++;
            k++;
        }
        while(j<n2){
            a[k]=R[j];
            j++;
            k++;
        }
    }
    public static void sort(long a[],int l,int r){
        int m;
        if(l<r){
            m=(l+r)/2;
            sort(a,l,m);
            sort(a,m+1,r);
            merge(a,l,m,r);
        }
    }
}

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int n = sc.nextInt();
    	char[] s = sc.next().toCharArray();
    	int min = Integer.MAX_VALUE;
    	for(int i=0; i<n-3; i++) {
    		int x = 0;
    		x += Math.min(Math.min(Math.abs('A' - s[i] + 26), Math.abs('A' - s[i])), Math.abs('A' - s[i] - 26));
    		x += Math.min(Math.min(Math.abs('C' - s[i+1] + 26), Math.abs('C' - s[i+1])), Math.abs('C' - s[i+1] - 26));
    		x += Math.min(Math.min(Math.abs('T' - s[i+2] + 26), Math.abs('T' - s[i+2])), Math.abs('T' - s[i+2] - 26));
    		x += Math.min(Math.min(Math.abs('G' - s[i+3] + 26), Math.abs('G' - s[i+3])), Math.abs('G' - s[i+3] - 26));
    		if(x < min) min = x;
    	}
    	System.out.println(min);
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    String a = s.next();
    int p=200;
    for(int i=0;i<n-3;i++)
    {
      int q=0;
      if((int)a.charAt(i)-65>=0)
      q=q+Math.min((int)a.charAt(i)-65, 91-(int)a.charAt(i));
      else
      q=q+Math.min(65-(int)a.charAt(i), (int)a.charAt(i)+26-65);
      if((int)a.charAt(i+1)-67>=0)
      q=q+Math.min(Math.abs((int)a.charAt(i+1)-67), 93-(int)a.charAt(i+1));
      else
      q=q+Math.min(Math.abs((int)a.charAt(i+1)-67), (int)a.charAt(i+1)-67+26);
      if((int)a.charAt(i+2)-84>=0)
      q=q+Math.min(Math.abs((int)a.charAt(i+2)-84), 110-(int)a.charAt(i+2));
      else
      q=q+Math.min(Math.abs((int)a.charAt(i+2)-84), (int)a.charAt(i+2)-84+26);
      if((int)a.charAt(i+3)-71>=0)
      q=q+Math.min(Math.abs((int)a.charAt(i+3)-71), 97-(int)a.charAt(i+3));
      else
      q=q+Math.min(Math.abs((int)a.charAt(i+3)-71), (int)a.charAt(i+3)-71+26);
      if(q<p)
      p=q;
    }
    System.out.println(p);
  }
}

import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;

public class Solution {

    static BigInteger modulo = new BigInteger("1000000007");

    static BigInteger exponentialModulo(BigInteger a, BigInteger b) {
        BigInteger previousNumber = BigInteger.ONE;
        while (!(b.equals(BigInteger.valueOf(0)))) {
            if (b.testBit(0)) {
                previousNumber = previousNumber.multiply(a).mod(modulo);
            }
            b = b.shiftRight(1);
            a = a.modPow(BigInteger.valueOf(2), modulo);
        }
        return previousNumber;
    }
    public static int foo(char a,char b){
        int raa = Math.abs(a-b);
        return Math.min(raa,26-raa);
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
       int t = input.nextInt();
       String s = input.next();

       int maxi = Integer.MAX_VALUE;
       for(int i = 0;i < s.length()-3;++i){
           maxi = Math.min(maxi,foo(s.charAt(i),'A')+foo(s.charAt(i+1),'C')+foo(s.charAt(i+2),'T')+foo(s.charAt(i+3),'G'));
       }
        System.out.println(maxi);
    }
}

//package solution;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Queue;
import java.math.*;
public class Solution {
      public static void main(String args[] ) throws Exception {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
             String f = bufferedReader.readLine();
             String t = bufferedReader.readLine();

               int n= Integer.parseInt(f);
               char[]d=t.toCharArray();

               int c=100000;
               for(int i=0;i<n-3;i++) {
               char[]w= {d[i],d[i+1],d[i+2],d[i+3]};
              int y=   Bfs(4,w);
               if(c>y)c=y;
               }
            System.out.print(c);
        }
static int Bfs(int n, char[] b) {
	   String a="ACTG";
    	char[]c=a.toCharArray();
    	String r=" ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY";
    	int d=0;
    	char[]f=r.toCharArray();
        for(int i=0;i<n;i++)
        {

        if(b[i]!=c[i]) {
        	int e1=Math.abs(r.indexOf(b[i])-r.indexOf(c[i]));//System.out.print(e1+" ");
        	int e2=Math.abs(r.indexOf(b[i])-r.lastIndexOf(c[i]));//System.out.println(e2+" "+r.indexOf(b[i])+" "+r.lastIndexOf(c[i]));
        	int e3=Math.abs(r.indexOf(c[i])-r.indexOf(b[i]));//System.out.print(e1+" ");

        	int e4=Math.abs(r.indexOf(c[i])-r.lastIndexOf(b[i]));//System.out.println(e2+" "+r.indexOf(b[i])+" "+r.lastIndexOf(c[i]));
        	int []e= {e1,e3,e2,e4};
        	Arrays.sort(e);

        	d+=e[0];

        }
        }
    // System.out.print(d+" ");
	return d;

}}

import java.io.*;
import java.util.*;
public class cp2 {
	public static void main(String args[]) {

			int n=II();
			char s[]=IS().toCharArray();
			char ch[]={'A', 'C', 'T', 'G'};

			int ans=Integer.MAX_VALUE;
			for(int i=0;i<=n-4;i++){
				int val=0;
				for(int j=i;j<i+4;j++){
					if(s[j]>ch[j-i])
						val=val+Math.min((int)s[j]-(int)ch[j-i], (int)'Z'-(int)s[j]+(int)ch[j-i]-(int)'A'+1);
					else
						val=val+Math.min((int)ch[j-i]-(int)s[j], (int)'Z'-(int)ch[j-i]+(int)s[j]-(int)'A'+1);
				}
				// System.out.println(val);
				ans=Math.min(ans, val);
			}
			System.out.println(ans);
	}

	static scan in=new scan(System.in);
	static int II() {
		return in.nextInt();
	}
	static long IL() {
		return in.nextLong();
	}
	static int[] IIA(int n) {
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=II();
		}
		return a;
	}
	static String IS() {
		return in.next();
	}
	static char IC(){
		return in.next().charAt(0);
	}
	static String[] ISA(int n) {
		String a[]=new String[n];
		for(int i=0;i<n;i++) {
			a[i]=IS();
		}
		return a;
	}
	static char[] ICA(int n) {
		char a[]=new char[n];
		for(int i=0;i<n;i++) {
			a[i]=IC();
		}
		return a;
	}
}
class scan
{
    public static BufferedReader reader;
    public static StringTokenizer token;

    scan(InputStream str)
    {
        reader=new BufferedReader(new InputStreamReader(str));
        token=null;
    }

    static int nextInt()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return Integer.parseInt(token.nextToken());
    }

    static long nextLong()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return Long.parseLong(token.nextToken());
    }

    static String next()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return token.nextToken();
    }

}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        String target = "ACTG";
        int global_min = Integer.MAX_VALUE;
        int local_min;

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();

        for (int i = 0; i <= n - 4; i++) {
            local_min = 0;
            for (int j = 0; j < 4; j++) {
                int temp = Math.abs(target.charAt(j) - s.charAt(i+j));
                local_min += Math.min(temp,26-temp);

            }

            if (local_min < global_min)
                global_min = local_min;
        }
        System.out.println(global_min);
    }
}

import java.io.*;
import java.math.*;
public class biology
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,j,n,c,mi;
  c=mi=0;
  char p,q;
  String a,b,s;
  b="ACTG";
  n=Integer.parseInt(in.readLine());
  s=in.readLine();
  for(i=0;i<=(n-4);i++)
  {
   a=s.substring(i,(i+4));
   c=0;
   for(j=0;j<4;j++)
   {
    p=a.charAt(j);
    q=b.charAt(j);
    if(p>q)
    c+=(int)Math.min((p-q),(q-p+26));
    else if(q>p)
    c+=(int)Math.min((q-p),(p-q+26));
   }
   if(i==0)
   mi=c;
   else if(c<mi)
   mi=c;
  }
  System.out.println(mi);
 }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws NumberFormatException, IOException {
		String s[] = br.readLine().trim().split(" ");
		int n = Integer.parseInt(s[0]);
		char[] c = br.readLine().trim().toCharArray();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = c[i]-'A';
		}
		int mndif = Integer.MAX_VALUE, dif = 0;
		for(int i = 0; i < n-3; i++) {
			dif = Math.min((26-a[i]), Math.abs(a[i]))+Math.min((28-a[i+1]), Math.abs(a[i+1]-2))+Math.min((7+a[i+2]), Math.abs(a[i+2]-19))+Math.min((32-a[i+3]), Math.abs(a[i+3]-6));
			if(mndif > dif) mndif = dif;
		}
		System.out.println(mndif);
	}
}

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int length = sc.nextInt();
        String s = sc.next();
        String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        ArrayList<Integer> minOps = new ArrayList<>();

        int indexA = letters.indexOf("A");
        int indexC = letters.indexOf("C");
        int indexT = letters.indexOf("T");
        int indexG = letters.indexOf("G");

        for (int i = 0; i <= length - 4; i++) {
            int a = letters.indexOf(s.charAt(i));
            int minA = Math.min(Math.abs(a - indexA), Math.min(Math.abs(26 + indexA - a), Math.abs(26 - indexA + a)));
            int c = letters.indexOf(s.charAt(i + 1));
            int minC = Math.min(Math.abs(c - indexC), Math.min(Math.abs(26 + indexC - c), Math.abs(26 - indexC + c)));
            int t = letters.indexOf(s.charAt(i + 2));
            int minT = Math.min(Math.abs(t - indexT), Math.min(Math.abs(26 + indexT - t), Math.abs(26 - indexT + t)));
            int g = letters.indexOf(s.charAt(i + 3));
            int minG = Math.min(Math.abs(g - indexG), Math.min(Math.abs(26 + indexG - g), Math.abs(26 - indexG + g)));
            int min = minA + minC + minG + minT;
            minOps.add(min);
        }
        out.println(Collections.min(minOps));

        out.close();
    }

    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author snehi
 */
public class MaximAndBiology {

    public static void main(String[] args) throws FileNotFoundException{
        FastReader fr = new FastReader();
        fr.nextLine();
        String sen = fr.nextLine();
        String chmk = "ACTG";
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < sen.length(); i++){
            int count = 0;
            if(sen.length()-i<4)break;
            for(int j = i; j < i+4; j++){
                int a = Math.abs(chmk.charAt(j-i)-sen.charAt(j));
                int b = Math.abs(Math.abs(chmk.charAt(j-i)-sen.charAt(j))-26);
                count += Math.min(a,b);
            }
            if(min > count){
                min = count;
            }
        }
        System.out.println((min != Integer.MAX_VALUE) ? min: 0);
    }
/*
    6
AFBAKC
  */
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    private static final String GENOME = "ACTG";
    private static final int TOTAL_CHAR = 26;
    private static int[][] dst;

    static {

        dst = new int[TOTAL_CHAR][TOTAL_CHAR];

        for (int i = 0; i < TOTAL_CHAR; i++) {

            int d = 1;
            dst[i][i] = 0;
            // before
            for (int j = i - 1; j >= 0; j--) {
                dst[i][j] = Math.min(d, TOTAL_CHAR - d);
                d++;

            }
            // after
            d = 1;
            for (int j = i + 1; j < TOTAL_CHAR; j++) {
                dst[i][j] = Math.min(d, TOTAL_CHAR - d);
                d++;
            }
        }
    }

    public static void main(String[] args) {
        Scanner I = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

        int n = I.nextInt();
        String s = I.next();
        int r = Integer.MAX_VALUE;

        for (int i = 0; i < n - 3; i++) {

            int p = 0, sm = 0;
            for (int j = i; j < i + 4; j++) {
                //System.out.println("dist for " + s.charAt(j) + " p " + p);
                sm = sm + dist(p, s.charAt(j));
                p++;
            }
            r = Math.min(r, sm);
        }

        System.out.println(r);

    }

    private static int dist(int position, Character from) {
        int u = Character.getNumericValue(from) - 10;
        int v = Character.getNumericValue(GENOME.charAt(position)) - 10;

        //System.out.println("Distance from " + from + " to " + GENOME.charAt(position) + " is " + d);

        return dst[u][v];
    }

}

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Sirius {
    public static void main(String[] args) throws IOException {
       Scanner scan = new Scanner(System.in);
       int n = scan.nextInt();
       scan.nextLine();
       char[] b = scan.nextLine().toCharArray();
       int min = 4;
       for(int i= 0; i+3 < b.length; ++i){
           int counter = 0;
           if(b[i] != 'A'){
               ++counter;
           }
           if(b[i+1] != 'C'){
               ++counter;
           }
           if(b[i+2] != 'T'){
               ++counter;
           }
           if(b[i+3] != 'G'){
               ++counter;
           }
           min = Math.min(counter, min);
       }
        System.out.println(min);
    }
}

//package solution;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Queue;
import java.math.*;
public class Solution {
      public static void main(String args[] ) throws Exception {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
             String f = bufferedReader.readLine();
             String t = bufferedReader.readLine();

               int n= Integer.parseInt(f);
               char[]d=t.toCharArray();

               int c=100000;
               for(int i=0;i<n-3;i++) {
               char[]w= {d[i],d[i+1],d[i+2],d[i+3]};
              int y=   Bfs(4,w);
              if(c>y)c=y;
               }
             System.out.print(c);
        }
static int Bfs(int n, char[] b) {
	   String a="ACTG";
    	char[]c=a.toCharArray();
    	String r=" ABCDEFGHIJKLMNOPKRSTUVWXYZABCDEFGHIJKLMNOPKRSTUVWXYZ";
    	int d=0;
    	char[]f=r.toCharArray();
        for(int i=0;i<n;i++)
        {

        if(b[i]!=c[i]) {
        	int e1=Math.abs(r.indexOf(b[i])-r.indexOf(c[i]));
        	int e2=Math.abs(r.indexOf(b[i])-r.lastIndexOf(c[i]));
        	if(e1>e2)d+=e2;
        	else d+=e1;

        }}
     //System.out.print(d);
	return d;

}}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author snehi
 */
public class MaximAndBiology {

    public static void main(String[] args) throws FileNotFoundException{
        FastReader fr = new FastReader();
        fr.nextLine();
        String sen = fr.nextLine();
        String chmk = "ACTG";
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < sen.length(); i++){
            int count = 0;
            if(sen.length()-i<4)break;
            for(int j = i; j < i+4; j++){
                count += Math.min(Math.abs(chmk.charAt(j-i)-sen.charAt(j)),
                        Math.abs(chmk.charAt(j-i)-sen.charAt(j)+25));
            }
            if(min > count){
                min = count;
            }
        }
        System.out.println((min != Integer.MAX_VALUE) ? min: 0);
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeMap;
/**
 *
 * @author yijieren
 */
public class Test {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        /*
        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String line2 = scn.nextLine();
        String[] t1 = line1.split(":");
        String[] t2 = line2.split(":");
        scn.close();

        int h1 = Integer.parseInt(t1[0]);
        int m1 = Integer.parseInt(t1[1]);
        int h2 = Integer.parseInt(t2[0]);
        int m2 = Integer.parseInt(t2[1]);
        */

        /*
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String string = scn.nextLine();
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String line = scn.nextLine();
        int n = Integer.parseInt(line);
        String[] arr = new String[n];
        for(int i=0; i<n; i++){
            arr[i] = scn.nextLine();
        }
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String[] tmp = line1.split(" ");

        String line2 = scn.nextLine();
        String[] tmp2 = line2.split(" ");
        scn.close();

        // 输入处理 && 得到数组中的最小值
        int n = Integer.parseInt(tmp[0]);
        int v = Integer.parseInt(tmp[1]);
        int[] nums = new int[n];
        int min = Integer.parseInt(tmp2[0]);
        for(int i=0; i<n; i++){
            nums[i] = Integer.parseInt(tmp2[i]);
            min = Math.min(min, nums[i]);
        }
        */

        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String str = scn.nextLine();
        int n = Integer.parseInt(line1);
        scn.close();

        int counter = 0;
        int result = Integer.MAX_VALUE;
        for(int i=0; i<=n-4; i++){
            counter += Math.min(Math.abs(str.charAt(i) - 'A'), 'Z'-str.charAt(i)+1);
            counter += Math.min(Math.abs(str.charAt(i+1) - 'C'), 'Z'-'C'+1+2);
            counter += Math.min(Math.abs(str.charAt(i+2) - 'T'), 'Z'-'T'+1+(str.charAt(i+2)-'A'));
            counter += Math.min(Math.abs(str.charAt(i+3) - 'G'), 'Z'-'G'+1+(str.charAt(i+3)-'A'));

            result = Math.min(counter, result);
            counter = 0;
        }

        System.out.println(result);

    }

}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class MaximAndBiology {

    public static void main(String[] args) throws FileNotFoundException{
        FastReader fr = new FastReader();
        fr.nextLine();
        String sen = fr.nextLine();
        String chmk = "ACTG";
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < sen.length(); i++){
            int count = 0;
            if(sen.length()-i<4)break;
            for(int j = i; j < i+4; j++){
                count += Math.abs(chmk.charAt(j-i)-sen.charAt(j));
            }
            if(min > count){
                min = count;
            }
        }
        System.out.println((min != Integer.MAX_VALUE) ? min: 0);
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javafx.css.StyleOrigin;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Quan2202
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int n = in.nextInt();
        String s = in.next();

        int min = 0;
        for (int i = 0; i < s.length() - 3; i++) {
            int a = Math.abs((int) s.charAt(i) - 'A');
            int b = Math.abs((int) s.charAt(i + 1) - 'C');
            int c = Math.abs((int) s.charAt(i + 2) - 'T');
            int d = Math.abs((int) s.charAt(i + 3) - 'G');
            //out.println(a+" "+b+" "+c+" "+d);
            int tmp = Math.min(a, 26 - a) + Math.min(b, 26 - b) + Math.min(c, 26 - c) + Math.min(d, 26 - d);
//            out.println(tmp);
//            out.println("------------------");
            if (min == 0) {
                min = tmp;
            } else if (tmp < min) {
                min = tmp;
            }

        }
        //print the result
        out.print(min);

        out.flush();
    }

    static class InputReader {

        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

import java.util.*;
public class MyClass {
    public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=1;
	while(t-->0) {
		int l=sc.nextInt();
		String str=sc.next();
		int ans=Integer.MAX_VALUE;
		for(int i=0;i<=str.length()-4;i++) {
			int temp=0;
			temp+=Math.min(Math.abs(str.charAt(i)-'A'), Math.abs('Z'-str.charAt(i)+1));
			if(str.charAt(i+1)>'C') {
				temp+=Math.min(Math.abs(str.charAt(i+1)-'C'), Math.abs('Z'-str.charAt(i+1)+('C'-'A'+1)));
			}else if(str.charAt(i+1)<'C') {
				temp+=Math.min(Math.abs(str.charAt(i+1)-'C'), Math.abs(str.charAt(i+1)-'A'+('Z'-'C'+1)));
			}
			if(str.charAt(i+2)>'T') {
				temp+=Math.min(Math.abs(str.charAt(i+2)-'T'), Math.abs('Z'-str.charAt(i+2)+('T'-'A'+1)));
			}else if(str.charAt(i+2)<'T') {
				temp+=Math.min(Math.abs(str.charAt(i+2)-'T'), Math.abs(str.charAt(i+2)-'A'+('Z'-'T'+1)));
			}
			if(str.charAt(i+3)>'G') {
				temp+=Math.min(Math.abs(str.charAt(i+3)-'G'), Math.abs('Z'-str.charAt(i+3)+('G'-'A'+1)));
			}else if(str.charAt(i)<'G') {
				temp+=Math.min(Math.abs(str.charAt(i+3)-'G'), Math.abs(str.charAt(i+3)-'A'+('Z'-'G'+1)));
			}
			ans=Math.min(ans, temp);
		}
		System.out.println(ans);
	}
   }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t,i,j=0,n,m,k=0,l,p,h,r;
		String s,st;
		n=in.nextInt();
		s=in.next();
		char c[]=s.toCharArray();
		int a[]=new int[n-3];
		for(i=0;i<n-3;i++)
		{
		     m=0;k=0;
		     m+=Math.abs(c[i]-'A')%24;
		     m+=Math.abs(c[i+1]-'C')%24;
		     m+=Math.abs(c[i+2]-'T')%24;
		     m+=Math.abs(c[i+3]-'G')%24;
		     k+=
		     a[i]=m;
		}
		Arrays.sort(a);
		System.out.println(a[0]);
	}
}

import java.util.*;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int min=999999999,sum;
		String astring=in.nextLine();
		String A=in.nextLine();
		char a[]=A.toCharArray();
		char g[]= {'A','C','T','G'};
		for(int i=0;i<n-3;i++)
		{
			sum=0;
			for(int j=i,k=0;k<4;j++,k++)
			{
				if(a[j]=='Z')
					sum+=Math.min('Z'-g[k], g[k]-'A'+1);
				else
					sum+=Math.abs(a[j]-g[k]);
			}
			if(min>sum)
				min=sum;
		}
		System.out.println(min);
	}
}

import java.io.PrintWriter;
import java.util.Scanner;

public class MaximandBiology {

	void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt();
		String s = in.next();

		int min = Integer.MAX_VALUE;
		// ACTG
		for (int i = 0; i <= n - 4; i++) {

			char[] a = s.substring(i, i + 4).toCharArray();
			int v = Math.min(Math.abs(a[0] - 'A'), Math.abs('Z' - a[0] + 'A' - 'A' + 1));
			v += Math.min(Math.abs(a[1] - 'C'), Math.abs('Z' - a[1] + 'C' - 'A' + 1));
			v += Math.min(Math.abs(a[2] - 'T'), Math.abs('Z' - a[2] + 'T' - 'A' + 1));
			v += Math.min(Math.abs(a[3] - 'G'), Math.abs('Z' - a[3] + 'G' - 'A' + 1));
			min = Math.min(min, v);

		}
		out.println(min);

	}

	void run() {
		try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);) {
			solve(in, out);
		}
	}

	public static void main(String args[]) {
		new MaximandBiology().run();
	}

}

import javax.sound.midi.SysexMessage;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.LinkedList;

/**
 * Created by assantoleuov on 12/25/16.
 */

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        solve(br);
        br.close();
    }

    private static void solve(BufferedReader br) throws IOException {
        String len = br.readLine();
        String word = br.readLine();
        int minVal = Integer.MAX_VALUE;
        for (int i = 0; i < word.length() - 3; i++) {
          int total = counter(word.charAt(i), 'A');
          total += counter(word.charAt(i+1), 'C');
          total += counter(word.charAt(i+2), 'T');
          total += counter(word.charAt(i+3), 'G');
          minVal = Math.min(minVal, total);
        }
        System.out.println(minVal);
    }

    private static int counter(char ch, char target) {
      return Math.min(Math.abs(ch - target), Math.abs('Z' - ch) + Math.abs(target - 'A') + 1);
    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Balloons
{
    public static void main (String[] args) throws java.lang.Exception
    {
    try {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int cool=1000000;
        char ch[]=br.readLine().toCharArray();
        for(int i=0;i<=n-4;i++)
        {
            int ans=0;
            if(ch[i]!='A')
            {
                if(ch[i]>'N')
                    ans+='Z'-ch[i]+1;
                else
                    ans+=ch[i]-'A';
            }
            if(ch[i+1]!='C')
            {
               if(ch[i+1]>'C' && ch[i+1]<'P')
                    ans+=ch[i+1]-'C';
                else
                    {
                        if(ch[i+1]>='P' && ch[i+1]<='Z')
                            ans+='Z'-ch[i+1]+2;
                        if(ch[i+1]>='A' && ch[i+1]<'C')
                            ans+='C'-ch[i+1];
                    }
            }
            if(ch[i+2]!='T')
            {
                if(ch[i+2]<'T' && ch[i+2]>'H')
                    ans+='T'-ch[i+2];
                else
                   { if(ch[i+2]>'T' && ch[i+2]<='Z')
                        ans+='Z'-ch[i+2];
                    if(ch[i+2]<='H' && ch[i+2]>='A')
                        ans+=ch[i+2]-'A'+6;}
            }
            if(ch[i+3]!='G')
            {
                if(ch[i+3]>'G' && ch[i+3]<'T')
                    ans+=ch[i+3]-'G';
                else
                    {
                        if(ch[i+3]>='U' && ch[i+3]<='Z')
                            ans+='Z'-ch[i+3]+6;
                        if(ch[i+3]<'G' && ch[i+3]>='A')
                            ans+='G'-ch[i+3];
                    }
            }
            if(cool>ans)
                cool=ans;
        }
        System.out.println(cool);
    } catch(Exception e) {
    return;}
    }
}

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        FastReader in = new FastReader();
        char[] gen = {'A', 'C', 'T', 'G'};
        int n = in.nextInt();
        char[] input = in.next().toCharArray();
        int best = Integer.MAX_VALUE;
        for (int i = 0; i <= n - 4; i++) {
            int count = 0;
            for (int j = i; j < i + 4; j++)
                if (input[j] != gen[j - i]) {
                    if(input[j] < gen[j-i]) input[j] += 26;
                    count += Math.min(Math.abs(input[j] - gen[j - i]), Math.abs(gen[j - i] - input[j] + 26));
                }
            best = Math.min(best, count);
        }
        System.out.println(best);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public int[] nextSortedIntArray(int n) {
            int array[] = nextIntArray(n);
            Arrays.sort(array);
            return array;
        }

        public int[] nextSumIntArray(int n) {
            int[] array = new int[n];
            array[0] = nextInt();
            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
            return array;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; ++i) array[i] = nextLong();
            return array;
        }

        public long[] nextSumLongArray(int n) {
            long[] array = new long[n];
            array[0] = nextInt();
            for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
            return array;
        }

        public long[] nextSortedLongArray(int n) {
            long array[] = nextLongArray(n);
            Arrays.sort(array);
            return array;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

		public String next() {
			if (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}
	}

	public static void main(String[] args)
	{
		FastReader sc=new FastReader();
		int n=sc.nextInt();
		String s=sc.next();
		int min=Integer.MAX_VALUE;
		for(int i=0;(i+3)<s.length();i++)
		{
			int temp=convert(s.substring(i,i+4));
			if(temp<min)
				min=temp;
		}
		System.out.println(min);
	}

	public static int convert(String s)
	{
		int o=0;
		int a=Math.min((int)s.charAt(0)-65,Math.abs(90-(int)s.charAt(0))+1);
		int c=Math.min(Math.abs((int)s.charAt(1)-67),Math.abs(24+(int)s.charAt(1))-65);
		int t=Math.min(Math.abs((int)s.charAt(2)-84),Math.abs(7+(int)s.charAt(2)-65));
		int g=Math.min(Math.abs((int)s.charAt(3)-71),Math.abs(20+(int)s.charAt(3))-65);
		o=a+c+t+g;

		return o;
	}

}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
public class S {
	public static void main (String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		String s=in.next();
		int min=Integer.MAX_VALUE;
		for(int i=0;i<=n-4;i++)
		{
		    int res=0;
		    if(s.charAt(i)!='A')
		    {
		        res+=Math.min('Z'-s.charAt(i)+1,s.charAt(i)-'A');
		    }
		    if(s.charAt(i+1)!='C')
		    {
		        res+=Math.min('Z'-s.charAt(i+1)+1+'C'-'A',Math.abs(s.charAt(i+1)-'C'));
		    }
		    if(s.charAt(i+2)!='T')
		    {
		        res+=Math.min('Z'-s.charAt(i+2)+1+'T'-'A',Math.abs(s.charAt(i+2)-'T'));
		    }
		    if(s.charAt(i+3)!='G')
		    {
		        res+=Math.min('Z'-s.charAt(i+3)+1+'G'-'A',Math.abs(s.charAt(i+3)-'G'));
		    }
		    min=Math.min(min,res);
		}
		System.out.print(min);
	}
}

import java.util.*;
import java.io.*;

 public final class A1151 {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int n = Integer.parseInt(br.readLine());

			String s = br.readLine();
			int ans = Integer.MAX_VALUE;
			for(int i = 0;i < n - 3; i++) {
				char ch = s.charAt(i);
				int tempAns = Math.min(Math.abs(ch - 'A'), Math.abs(26 - (ch - 'A')));
				ch = s.charAt(i + 1);
				tempAns += Math.min(Math.abs(ch - 'C'), Math.abs(26 - (ch - 'C')));
				ch = s.charAt(i + 2);
				tempAns += Math.min(Math.abs(ch - 'T'), Math.abs(26 - (ch - 'T')));
				ch = s.charAt(i + 3);
				tempAns += Math.min(Math.abs(ch - 'G'), Math.abs(26 - (ch - 'G')));
				if(tempAns < ans) {
					ans = tempAns;
				}

			}
			System.out.println(ans);

	}

}

	import java.io.BufferedOutputStream;
	import java.io.BufferedReader;
	import java.io.InputStreamReader;
	import java.io.PrintWriter;
	import java.util.*;

	public class e {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	static ArrayList<String>list1=new ArrayList<String>();
	static void combine(String instr, StringBuffer outstr, int index,int k)
	{
		if(outstr.length()==k)
		{
			list1.add(outstr.toString());return;
		}
		if(outstr.toString().length()==0)
		outstr.append(instr.charAt(index));
	    for (int i = 0; i < instr.length(); i++)
	    {
	        outstr.append(instr.charAt(i));

	        combine(instr, outstr, i + 1,k);
	        outstr.deleteCharAt(outstr.length() - 1);
	    }
	   index++;
	}
	static ArrayList<ArrayList<Integer>>l=new ArrayList<>();
	static void comb(int n,int k,int ind,ArrayList<Integer>list)
	{
		if(k==0)
		{
			l.add(new ArrayList<>(list));

			return;
		}

		for(int i=ind;i<=n;i++)
		{
			list.add(i);
			comb(n,k-1,ind+1,list);

			list.remove(list.size()-1);

		}

	}
	static int getans(int a,int b)
	{int ct=0;
		while(a<b)
		{
			b/=2;ct++;
			if(a==b)
				break;
		}
		if(a==b)
		return ct;
		else
			return 0;

	}
	static class Pair implements Comparable<Pair>{
	    int x;int y;
	    Pair(int x,int y){
	        this.x=x;
	        this.y=y;
	      //  this.i=i;
	    }
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			return x-o.x;

		}
	}
	static int givenum(int a,int b,int k)
	{
		if(a==-1&&b==-1)
		{
			return 1;
		}
		else if(a==-1)
		{
			for(int i=1;i<=k;i++)
				if(i!=b)
					return i;
		}
		else if(b==-1)
		{
			for(int i=1;i<=k;i++)
				if(i!=a)
					return i;
		}
		else
		{
			for(int i=1;i<=k;i++)
		{
			if(i!=a&&i!=b)
				return i;
		}
			}
		return -1;
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	  static HashMap<Long, Pair> sort(HashMap<Long, Pair> hm)
	    {
	        // Create a list from elements of HashMap
	        List<Map.Entry<Long, Pair> > list =
	               new LinkedList<Map.Entry<Long, Pair> >(hm.entrySet());

	        // Sort the list
	        Collections.sort(list, new Comparator<Map.Entry<Long, Pair> >() {
	            public int compare(Map.Entry<Long, Pair> o1,
	                               Map.Entry<Long, Pair> o2)
	            {
	                return (o1.getValue().y)-(o2.getValue().y);
	            }
	        });

	        // put data from sorted list to hashmap
	        HashMap<Long, Pair> temp = new LinkedHashMap<Long, Pair>();
	        for (Map.Entry<Long, Pair> aa : list) {
	            temp.put(aa.getKey(), aa.getValue());
	        }
	        return temp;
	    }
		public static void main(String[] args) {
			// TODO Auto-generated method stub

		FastReader in=new FastReader();
	HashMap<Long,Pair>map=new HashMap<Long,Pair>();

	String gen="actg";
	int n=in.nextInt();
	String s=in.next().toLowerCase();
	int ans=Integer.MAX_VALUE;
	for(int i=0;i<n-3;i++)
	{	int y=0;
		String sr=s.substring(i,i+4);
		for(int j=0;j<4;j++)
		{char ge=gen.charAt(j);
			char ch=sr.charAt(j);
			y+=Math.min(Math.abs(ch-ge), Math.abs(26-ch+ge));
		}
		ans=Math.min(y, ans);
	}
	out.println(ans);out.close();

		}
	}

// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.*;

public class Main
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
         FastReader sc=new FastReader();
         int n=sc.nextInt();
         String s=sc.next();
         StringBuilder sb=new StringBuilder(s);
         int i;
         int min=Integer.MAX_VALUE;
         int sol=0;
         for(i=0;i<(n-3);i++)
         {
             int diff1,diff2;
             diff1=Math.abs(sb.charAt(i)-'A');
             diff2=Math.abs('Z'-sb.charAt(i)+('A'-64));
             sol=sol+Math.min(diff2,diff1);

             diff1=Math.abs(sb.charAt(i+1)-'C');
             diff2=Math.abs('Z'-sb.charAt(i+1)+('C'-64));
             sol=sol+Math.min(diff2,diff1);

             diff1=Math.abs(s.charAt(i+2)-'T');
             diff2=Math.abs('Z'-sb.charAt(i)+('T'-64));
             sol=sol+Math.min(diff2,diff1);

             diff1=Math.abs(sb.charAt(i+3)-'G');
             diff2=Math.abs('Z'-sb.charAt(i)+('G'-64));
             sol=sol+Math.min(diff2,diff1);
             if(sol<min)
             min=sol;
             sol=0;
         }
         System.out.println(min);
    }
}

//package codechef_long;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;

public class shashwat
{ static Scanner in=new Scanner(System.in);
static class data{
	int data;
	int index;
}
	public static void main(String[] args) throws IOException
	{
		/*int row=in.nextInt();
		int col=in.nextInt();
		int arr[][]=new int[row][col];
		HashSet<data> hlist[]=new HashSet[row];

		for(int i=0;i<row;i++){
		hlist[i]=new HashSet<data>();
		hlist[i].index=i;
		    for(int j=0;j<col;j++)
		         {
		             arr[i][j]=in.nextInt();
		             if(!hlist[i].contains(arr[i][j]))
		                hlist[i].add(arr[i][j]);
		         }
		}
		for(int i=0;i<row;i++){
		  for(int x:hlist[i])
		        System.out.print(x+" ");
		  System.out.println();
		}
		HashSet<Integer> akash=new HashSet<Integer>();
		for(int i=0;i<row;i++) {
			for(int x:hlist[i])
			if(!akash.contains(x))
                akash.add(x);

		}
		for(int x:akash)
			System.out.println(x);
	*/
		int n=in.nextInt();
		String s=in.next();
		String ak="ACTG";
		if(s.equals(ak))
			System.out.println("0");
		else {
			int max=Integer.MAX_VALUE;
			int ch[]=new int[n];

			for(int i=0;i<=n-4;i++)
			{
				int sum=0;
				sum+=(int)Math.abs(s.charAt(i)-'A')%24;
				sum+=(int)Math.abs(s.charAt(i+1)-'C')%24;
				sum+=(int)Math.abs(s.charAt(i+2)-'T')%24;
				sum+=(int)Math.abs(s.charAt(i+3)-'G')%24;
				//System.out.println(sum);
				if(sum<max)
					max=sum;
			}
			System.out.println(max);
		}
		}
}

import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Test {

    public static void main(String... args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), to[][] = new int[26][4], ans = (int)2e10;
        char a[] = in.next().toCharArray(), u[] = {'A', 'C', 'T', 'G'};

        for(int i = 0; i<26; i++){
            for(int j = 0; j<4; j++){
                char now = (char)('A'+i);
                to[i][j] = min(abs(now-u[j]), abs('Z'-now+(u[j]-'A')+1));
            }
        }

        for(int i = 0; i<n-3; i++){
            int t = to[a[i]-'A'][0]+to[a[i+1]-'A'][1]+to[a[i+2]-'A'][2]+to[a[i+3]-'A'][3];
            ans = min(ans, t);
        }
        System.out.print(ans);

    }

    static class Pair{
        long x, y;
        Pair(long a, long b){
            x = a; y = b;
        }
    }
}

import java.util.*;
import static java.lang.Math.*;

public class Test {

    public static void main(String... args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), ans = 100000000;
        char c[] = in.next().toCharArray();

        for(int i = 0; i<n-3; i++){
            int a[] = {abs((int)c[i]-(int)'A'), abs((int)c[i+1]-(int)'C'), abs((int)c[i+2]-(int)'T'), abs((int)c[i+3]-(int)'G')};
            if(a[0]==25) a[0]=1;

            ans = min(a[0]+a[1]+a[2]+a[3], ans);
        }
        System.out.print(ans);
    }
}

import java.util.*;
import java.io.*;

public final class A1151 {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int n = Integer.parseInt(br.readLine());

			String s = br.readLine();
			long ans = Integer.MAX_VALUE;
			for(int i = 0;i < n - 3; i++) {
				char ch = s.charAt(i);
				long tempAns = Math.min(Math.abs(ch - 'A'), Math.abs(26 - Math.abs(ch - 'A')));
				System.out.println(tempAns);
				ch = s.charAt(i + 1);
				tempAns += Math.min(Math.abs(ch - 'C'), Math.abs(26 - Math.abs(ch - 'C')));
				System.out.println(Math.min(Math.abs(ch - 'C'), Math.abs(26 - Math.abs(ch - 'C'))));

				ch = s.charAt(i + 2);
				tempAns += Math.min(Math.abs(ch - 'T'), Math.abs(26 - Math.abs(ch - 'T')));
				System.out.println(Math.min(Math.abs(ch - 'T'), Math.abs(26 - Math.abs(ch - 'T'))));

				ch = s.charAt(i + 3);
				tempAns += Math.min(Math.abs(ch - 'G'), Math.abs(26 - Math.abs(ch - 'G')));
				System.out.println(Math.min(Math.abs(ch - 'G'), Math.abs(26 - Math.abs(ch - 'G'))));
				if(tempAns < ans) {
					ans = tempAns;
				}

			}
			System.out.println(ans);

	}

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class maximandbiology {

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		int n = Integer.parseInt(in.readLine());

		char[] chars = in.readLine().toCharArray();
		char[] g = {'A', 'C', 'T', 'G'};

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n - 3; i++) {
			int cost = Math.abs(g[0] - chars[i]) + Math.abs(g[1] - chars[i+1]) + Math.abs(g[2] - chars[i+2]) + Math.abs(g[3] - chars[i+3]);
			min = Math.min(min, cost);
		}

		out.println(min);

		in.close();
		out.close();
	}

}

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int n = sc.nextInt();
    	char[] s = sc.next().toCharArray();
    	int min = Integer.MAX_VALUE;
    	for(int i=0; i<n-3; i++) {
    		int x = 0;
    		x += Math.min(Math.abs('A' - s[i] + 26), Math.abs('A' - s[i]));
    		x += Math.min(Math.abs('C' - s[i+1] + 26), Math.abs('C' - s[i+1]));
    		x += Math.min(Math.abs('T' - s[i+2] + 26), Math.abs('T' - s[i+2]));
    		x += Math.min(Math.abs('G' - s[i+3] + 26), Math.abs('G' - s[i+3]));
    		if(x < min) min = x;
    	}
    	System.out.println(min);
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        char[] template = new char[]{'A', 'C', 'T', 'G'};
        int num_cycle = (n / 4) + (n % 4);

        int res = Integer.MAX_VALUE;
        String str = scanner.next();

        for (int i = 0; i < num_cycle; i++) {
            int min_num_op = 0;
            char[] ch = str.substring(i, i + 4).toCharArray();
            for (int k = 0; k < ch.length; k++) {
                int left = Math.abs(template[k] - ch[k]);
                int right = 26 - left;
                min_num_op += Math.min(left, right);
            }
            if (res > min_num_op) res = min_num_op;
        }

        System.out.println(res);
    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t,i,j=0,n,m,k=0,l,p,h,r;
		String s,st;
		n=in.nextInt();
		s=in.next();
		char c[]=s.toCharArray();
		int a[]=new int[n-3];
		for(i=0;i<n-3;i++)
		{
		     m=0;k=0;
		     m+=Math.abs(c[i]-'A')%24;
		     m+=Math.abs(c[i+1]-'C')%24;
		     m+=Math.abs(c[i+2]-'T')%24;
		     m+=Math.abs(c[i+3]-'G')%24;
		     a[i]=m;
		}
		Arrays.sort(a);
		System.out.println(a[0]);
	}
}

import java.lang.reflect.Array;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.io.*;
import java.math.*;

public class CC
{
    static class pair implements Comparable<pair>
    {
        int x;
        long y;
        pair(int x,long y)
        {
            this.x=x;
            this.y=y;
        }
        public int compareTo(pair o)
        {
            return (int)(y-o.y);
        }

    }
    static ArrayList<Long>num=new ArrayList<>();
    static void printPermutn(String str, String ans)
    {

        // If string is empty
        if (str.length() == 0) {
            num.add(Long.valueOf(ans));
            return;
        }

        for (int i = 0; i < str.length(); i++)
        {

            // ith character of str
            char ch = str.charAt(i);

            // Rest of the string after excluding
            // the ith character
            String ros = str.substring(0, i) +
                    str.substring(i + 1);

            // Recurvise call
            printPermutn(ros, ans + ch);
        }
    }

    public static void main(String[] args)
    {
        StringBuffer sb = new StringBuffer();
        int t=i();
      char c[]=s().toCharArray();
      int operation=Integer.MAX_VALUE;
      for(int i=0;i<=t-4;i++)
      {
          int op=0;

         op+=Math.min(Math.abs((c[i]-'A')),Math.abs(('A'-c[i]+26)));

          op+=Math.min(Math.abs((c[i+1]-'C')),Math.abs(('C'-c[i+1]+26)));
          op+=Math.min(Math.abs((c[i+2]-'T')),Math.abs(('T'-c[i+2]+26)));
          op+=Math.min(Math.abs((c[i+3]-'G')),Math.abs(('G'-c[i]+26)));
          operation=Math.min(op,operation);
      }

     sb.append(operation+"\n");

        System.out.println(sb.toString());
    }

 //********************************Class pair******************************************************************************************************************************************///////////////////////////////////////////////////////////////////////////////////////////////

//-------------------prime factorization********/***************************************************************************************************************************************///////////////////////////////////
static TreeMap primefactorize(long n)
{
    TreeMap<Integer,Integer>h=new TreeMap<>();
    long number=n;
    for(int i=2;i<=Math.sqrt(n);i++)
    {
        if(n%i==0)
        {
            int cnt=0;
            while(n%i==0)
            {
                n=n/i;
                cnt++;
            }
            h.put(i,cnt);
        }
    }
    if(n!=1)
        h.put((int)n,1);
    return h;
}
///******************************SYSTEM PART*****************************************************************************************************************************************************************************************************************************************************////
    static InputReader in=new InputReader(System.in);
    static OutputWriter out=new OutputWriter(System.out);

    public static long pow(long a, long b)
    {
        long result=1;
        while(b>0){
            if (b % 2 != 0){
                result=(result*a);
                b--;
            }
            a=(a*a);
            b /= 2;
        }
        return result;
    }
    public static long gcd(long a, long b){
        if (a == 0){
            return b;
        }
        return gcd(b%a, a);
    }
    public static long lcm(long a, long b){
        return a*(b/gcd(a,b));
    }
    public static long l(){
        String s=in.String();
        return Long.parseLong(s);
    }
    public static void pln(String value){
        System.out.println(value);
    }
    public static int i(){
        return in.Int();
    }
    public static String s(){
        return in.String();
    }
}
///******************input Reader//***************************************************************************************************************************************************************************************
class InputReader
{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
    public InputReader(InputStream stream) {
        this.stream = stream;
    }
    public int read() {
        if (numChars== -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public int Int() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public String String() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    public String next() {
        return String();
    }
    public interface SpaceCharFilter
    {
        public boolean isSpaceChar(int ch);
    }
}

//*******************OUTPUT WRITER********************************************************************************************************************************************************************************************************************************************************//
class OutputWriter {
    private final PrintWriter writer;
    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }
    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }
    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }
    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }
    public void close() {
        writer.close();
    }
    public void flush() {
        writer.flush();
    }
}

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigInteger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.TreeSet;

public final class CF_553_D2_A
{

	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}

	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static void process() throws Exception {

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);

		int L=reader.readInt();
		String s=reader.readString();
		String ref="ACTG";

		int best=Integer.MAX_VALUE;
		for (int i=0;i+4<=L;i++){
			int diff=0;
			for (int u=0;u<4;u++){
				int x=s.charAt(i+u)-'A';
				int y=ref.charAt(u)-'A';
				diff+=Math.min(Math.abs(x-y),Math.abs(26-x+y));
			}
			if (diff<best)
				best=diff;
		}
		output(best);

		try {
			out.close();
		} catch (Exception e) {
		}

	}

	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class MaximandBiology {
	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine());
		int x = Integer.parseInt(stringTokenizer.nextToken());
		stringTokenizer = new StringTokenizer(bufferedReader.readLine());
		String desk = "ACTG";
		int flag = Integer.MAX_VALUE;
		String string = stringTokenizer.nextToken();
		for (int i = 0; i < string.length(); i++) {
			if (i + 4 <= string.length()) {
				int s = 0;
				int max = 0;
				int o = 0;
				while (s <= 3) {
					max += Math.min(Math.abs((string.charAt(i + s) - 'A') - (desk.charAt(s) - 'A')), Math.abs((desk.charAt(s) - 'A') - (string.charAt(i + s) - 'A') + 26));
					s++;
				}
				if (flag > max) {
					flag = max;
				}
			}

		}
		System.out.println(flag);
		bufferedReader.close();
	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Code
{
    public static void main (String[] args) throws java.lang.Exception
    {
    try {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int cool=1000000;
        char ch[]=br.readLine().toCharArray();
        for(int i=0;i<=n-4;i++)
        {
            int ans=0;
            if(ch[i]!='A')
            {
                if(ch[i]>'N')
                    ans+='Z'-ch[i]+1;
                else
                    ans+=ch[i]-'A';

               // System.out.println(ans);
            }
            if(ch[i+1]!='C')
            {
               if(ch[i+1]>'C' && ch[i+1]<'P')
                    ans+=ch[i+1]-'C';
                else
                    {
                        if(ch[i+1]>='P' && ch[i+1]<='Z')
                            ans+='Z'-ch[i+1]+3;
                        if(ch[i+1]>='A' && ch[i+1]<'C')
                            ans+='C'-ch[i+1];
                    }
              //  System.out.println(ans);
            }
            if(ch[i+2]!='T')
            {
                if(ch[i+2]<'T' && ch[i+2]>'H')
                    ans+='T'-ch[i+2];
                else
                   { if(ch[i+2]>'T' && ch[i+2]<='Z')
                        ans+='Z'-ch[i+2];
                    if(ch[i+2]<='H' && ch[i+2]>='A')
                        ans+=ch[i+2]-'A'+7;}
          // System.out.println(ans);
            }
            if(ch[i+3]!='G')
            {
                if(ch[i+3]>'G' && ch[i+3]<='T')
                    ans+=ch[i+3]-'G';
                else
                    {
                        if(ch[i+3]>='U' && ch[i+3]<='Z')
                            ans+='Z'-ch[i+3]+7;
                        if(ch[i+3]<'G' && ch[i+3]>='A')
                            ans+='G'-ch[i+3];
                    }

                //System.out.println(ans);
            }

            if(cool>ans)
                cool=ans;
        }
        System.out.println(cool);
    } catch(Exception e) {
    return;}
    }
}

import java.io.*;

public class Codechef
{
	public static void main (String[] args) throws IOException
	{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=1;//Integer.parseInt(br.readLine().trim());
        while((t--)>0)
        {
                int n=Integer.parseInt(br.readLine().trim());
                String s=br.readLine().trim();
                int min=Integer.MAX_VALUE;
        		for(int i=0;i<n-3;i++)
        		{
        		    int temp=fun(s,i);
        		    if(min>temp)
        		        min=temp;
        		}
        	   System.out.println(min);
            }
	}
	static int fun(String s,int i)
    {

        int a=(int)Math.min(Math.abs(s.charAt(i)-'A'),Math.abs(s.charAt(i)-65));
        int b=(int)Math.min(Math.abs(s.charAt(i+1)-'C'),Math.abs(s.charAt(i+1)-65+24));
        int c=(int)Math.min(Math.abs(s.charAt(i+2)-'T'),Math.abs(s.charAt(i+2)-65+7));
        int d=(int)Math.min(Math.abs(s.charAt(i+3)-'G'),Math.abs(s.charAt(i+3)-65+20));
        if(a==25)
            a=1;
        if(b==25)
            b=1;
        if(c==25)
            c=1;
        if(d==25)
            d=1;
        return a+b+c+d;
    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class codeforces {

	public static void main(String args[])
	{

		Scanner in = new Scanner(System.in);
	    int n=in.nextInt();
	    int i=0,j=0;
	    String s= in.next();
	    boolean status=false;
	    int min = Integer.MAX_VALUE;
	    int sum=0;
	    if(s.contains("ACTG"))
	    {
	    	System.out.println("0");
	    	System.exit(0);
	    }

	    else
	    {
	    	for(i=0;i<s.length();i++)
	    	{
	    		j=i;
	    		    if((j+3)<s.length())
	    		    {
	    		    	 sum= (Math.min(Math.abs(s.charAt(j) - 'A'),Math.abs(91-s.charAt(j))))
	    		    			+ (Math.min(Math.abs(s.charAt(j+1) - 'C'),Math.abs(93-s.charAt(j+1))))
	    		    			+ (Math.min(Math.abs(s.charAt(j+2) - 'T'),Math.abs(s.charAt(j+2)+26-'T')))
	    		    			+ (Math.min(Math.abs(s.charAt(j+3) - 'G'),Math.abs(s.charAt(j+3)+26-'G')));

	    		    /*System.out.print((Math.min(Math.abs(s.charAt(j) - 'A'),Math.abs(91-s.charAt(j))))+" ");
	    		    System.out.print((Math.min(Math.abs(s.charAt(j+1) - 'C'),Math.abs(93-s.charAt(j+1))))+" ");
	    		    System.out.print((Math.min(Math.abs(s.charAt(j+2) - 'T'),Math.abs(s.charAt(j+2)+26-'T')))+" ");
	    		    System.out.print((Math.min(Math.abs(s.charAt(j+3) - 'G'),Math.abs(s.charAt(j+3)+26-'G')))+" ");
	    		    System.out.println(sum);*/
	    		    }
	    		    if((j+3)>=s.length())
	    		    {
	    		    	status=true;
	    		    	break;
	    		    }

	    		if(sum<min)
	    		{
	    			min=sum;
	    		}
	    	}
	    }
	    System.out.println(min);

	}

}

import java.util.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringTokenizer;

public class temp {

int get(String s)
{
	int ans = 0;
	if(s.charAt(0)!='A')
		ans+=Math.min(s.charAt(0) - 'A' , 'Z' - s.charAt(0) + 1);
	if(s.charAt(1)!='C')
		ans+=Math.min(Math.abs(s.charAt(1) - 'C') , 'Z' - s.charAt(1) + ('C' - 'A') + 1);
	if(s.charAt(2)!='T')
		ans+=Math.min(Math.abs(s.charAt(2) - 'T') , 'Z' - s.charAt(2) + ('T' - 'A') + 1);
	if(s.charAt(3)!='G')
		ans+=Math.min(Math.abs(s.charAt(3) - 'G') , 'Z' - s.charAt(3) + ('G' - 'A')+1);

	return ans;
}

void solve() throws IOException
    {
       FastReader sc = new FastReader();
       int n = sc.nextInt();
       String s = sc.next();

       int ans = Integer.MAX_VALUE;
       for(int i=0;i<=s.length()-4;i++)
    	   ans = Math.min(ans,get(s.substring(i,i+4)));

       System.out.println(ans);
   }

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        new temp().solve();
    }

    class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class stringprob
{

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        sc.nextLine();
        String s=sc.nextLine();
        int min=Integer.MAX_VALUE;
        for(int j=0;j<n-4+1;j++)
        {
            int res=0;
            int c1=Math.min(Math.abs((int)s.charAt(j)-65),Math.abs(((int)s.charAt(j)-65)-26));
            int c2=Math.min(Math.abs((int)s.charAt(j+1)-67),Math.abs(26-(int)s.charAt(j+1)-67));
            int c3=Math.min(Math.abs((int)s.charAt(j+2)-84),Math.abs(26-(int)s.charAt(j+2)-84));
            int c4=Math.min(Math.abs((int)s.charAt(j+3)-71),Math.abs(26-(int)s.charAt(j+3)-71));

            res=c1+c2+c3+c4;
            if(res<min)
                min=res;
        }
        System.out.println(min);

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class MaximandBiology {
	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine());
		int x = Integer.parseInt(stringTokenizer.nextToken());
		stringTokenizer = new StringTokenizer(bufferedReader.readLine());
		String desk = "ACTG";
		int flag = Integer.MAX_VALUE;
		String string = stringTokenizer.nextToken();
		for (int i = 0; i < string.length(); i++) {
			if (i + 4 <= string.length()) {
				int s = 0;
				int max = 0;
				int o = 0;
				while (s <= 3) {
					max += Math.min(Math.abs((string.charAt(i + s) - 'A') - (desk.charAt(s) - 'A')), Math.abs((desk.charAt(s) - 'A') - (string.charAt(i + s) - 'A') + 26));
					s++;
				}
				if (flag > max) {
					flag = max;
				}
			}
		}
		if (flag == Integer.MAX_VALUE) {
			System.out.println(0);
		} else {
			System.out.println(flag);
		}
		bufferedReader.close();
	}
}

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Sirius {
    public static void main(String[] args) throws IOException {
       Scanner scan = new Scanner(System.in);
       int n = scan.nextInt();
       scan.nextLine();
       char[] b = scan.nextLine().toCharArray();
       int min = 4;
       for(int i= 0; i+3 < b.length; ++i){
           int counter = 0;
           if(b[i] != 'A'){
               ++counter;
           }
           if(b[i+1] != 'C'){
               ++counter;
           }
           if(b[i+2] != 'T'){
               ++counter;
           }
           if(b[i+3] != 'G'){
               ++counter;
           }
           min = Math.min(counter, min);
       }
        System.out.println(min);
    }
}

import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;

public class Solution {

    static BigInteger modulo = new BigInteger("1000000007");

    static BigInteger exponentialModulo(BigInteger a, BigInteger b) {
        BigInteger previousNumber = BigInteger.ONE;
        while (!(b.equals(BigInteger.valueOf(0)))) {
            if (b.testBit(0)) {
                previousNumber = previousNumber.multiply(a).mod(modulo);
            }
            b = b.shiftRight(1);
            a = a.modPow(BigInteger.valueOf(2), modulo);
        }
        return previousNumber;
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = Integer.parseInt(input.nextLine().trim());
        String s = input.next();
        if (s.contains("ACTG")) {
            System.out.println(0);
        } else {

            int ans = 0;
            int p = Integer.MAX_VALUE;
            for(int i = 0;i < s.length()-3;++i){
                ans = Math.min(s.charAt(i)-'A', 91%s.charAt(i));
                ans += Math.min(Math.abs(s.charAt(i+1)-'C'),91%s.charAt(i+1));
                ans += Math.min(Math.abs(s.charAt(i+2)-'T'),91%s.charAt(i+2));
                ans += Math.min(Math.abs(s.charAt(i+3)-'G'),91%s.charAt(i+3));
              p = Math.min(ans, p);
            }
            System.out.println(p);
        }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.lang.Math;

public class M {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String b = reader.readLine();
        String[] x = reader.readLine().split("");
        List<String> m = new ArrayList<>();
        m.add("A");
        m.add("C");
        m.add("T");
        m.add("G");

        long min = Integer.MAX_VALUE;
        for (int i = 0; i + 3 < x.length; i++) {
            long res = 0;
            if (!x[i].equals("A")) {

                res += need(x[i], 0);
            }
            if (!x[i + 1].equals("C")) {

                res += need(x[i + 1], 1);
            }
            if (!x[i + 2].equals("T")) {

                res += need(x[i + 2], 2);
            }
            if (!x[i + 3].equals("G")) {
                res += need(x[i + 3], 3);
            }

            if(min>res)min =res;
        }
        System.out.println(min);
    }

    static char[] j = {'A', 'C', 'T', 'G'};

    static int need(String x, int pos) {
        char first = j[pos];
        char second = x.toCharArray()[0];
        int res = first - second;
        if (second>first){
            res = Math.min(first+26-second,second-first);
        }
        return res;
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Queue;
import java.math.*;
public class Solution {
      public static void main(String args[] ) throws Exception {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
             String f = bufferedReader.readLine();
             String t = bufferedReader.readLine();

               int n= Integer.parseInt(f);
               char[]d=t.toCharArray();
              char[]w= {d[n-4],d[n-3],d[n-2],d[n-1]};

              Bfs(4,w);

        }
static void Bfs(int n, char[] b) {
	   String a="ACTG";
    	char[]c=a.toCharArray();
    	String r=" ABCDEFGHIJKLMNOPKRSTUVWXYZABCDEFGHIJKLMNOPKRSTUVWXY";
    	int d=0;
    	char[]f=r.toCharArray();
        for(int i=0;i<n;i++)
        {

        	int e1=Math.abs(r.indexOf(b[i])-r.indexOf(c[i]));
        	int e2=Math.abs(r.indexOf(b[i])-r.lastIndexOf(c[i]));
        	if(e1>e2)d+=e2;
        	else d+=e1;

        }
     System.out.print(d);

}}

import java.io.*;
import java.util.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static final double EPS = 1e-9;
	static int mod = 1000000007;
	static int inf = (int) 1e9 + 2;
	static long[] fac;
	static int[] si;
	static ArrayList<Integer> primes;
	static ArrayList<Integer>[] ad;
	static int[] ans;
	static int m, k;
	static HashMap<Integer, Integer> t;
	static boolean f;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n=sc.nextInt();
		int ans=Integer.MAX_VALUE;
		char[]a=sc.nextLine().toCharArray();
		char []b= {'A','C','T','G'};
		for(int i=0;i<n;i++) {
			if(i+3>=n)
				break;
			int tmp=0;
			tmp+=Math.min(a[i]-'A',Math.abs('Z'-a[i]+1));
			if(a[i+1]>='C')
				tmp+=Math.min(a[i+1]-'C',Math.abs('Z'-a[i+1]+1+'A'-'C'));
			else
				tmp+=Math.min('C'-a[i+1],'Z'-'C'+a[i+1]-'A'+1);
			if(a[i+2]>='T')
				tmp+=Math.min(a[i+2]-'T',Math.abs('Z'-a[i+2]+1+'A'-'T'));
			else
				tmp+=Math.min('T'-a[i+2],'Z'-'T'+a[i+2]-'A'+1);
			if(a[i+3]>='G')
				tmp+=Math.min(a[i+3]-'G',Math.abs('Z'-a[i+3]+1+'A'-'G'));
			else
				tmp+=Math.min('G'-a[i+3],'Z'-'G'+a[i+3]-'A'+1);
			ans=Math.min(ans, tmp);
		}
		out.println(ans);
		out.close();
	}

	static class seg implements Comparable<seg> {
		int s;
		int e;
		int num;
		int id;

		seg(int s, int e) {
			this.s = s;
			this.e = e;
		}

		public String toString() {
			return s + " " + e + " " + num + " " + id;
		}

		@Override
		public int compareTo(seg o) {
			if (o.s == s)
				return o.e - e;
			return s - o.s;
		}
	}

	static public class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy, candies;

		SegmentTree(int[] in) {
			array = in.clone();
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			candies = new int[N << 1];
			build(1, 1, N);
			build2(1, 1, N);
		}

		public String toString() {
			return Arrays.toString(sTree) + "\n" + Arrays.toString(candies);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = (sTree[node << 1] + sTree[node << 1 | 1]) % 10;
				if (sTree[node << 1] + sTree[node << 1 | 1] >= 10)
					candies[node]++;
			}
		}

		void build2(int node, int b, int e) // O(n)
		{
			if (b == e)
				b = e;
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				candies[node] = (candies[node << 1] + candies[node << 1 | 1]);
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		// static int c=0;
		int query(int i, int j) {
			// c=0;
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return candies[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;
		}
	}

	static int x, y, d;

	static long power(int i) {
		// if(i==0)
		// return 1;
		long a = 1;
		for (int k = 0; k < i; k++)
			a *= i;
		return a;
	}

	static void extendedEuclid(int a, int b) {
		if (b == 0) {
			x = 1;
			y = 0;
			d = a;
			return;
		}
		extendedEuclid(b, a % b);
		int x1 = y;
		int y1 = x - a / b * y;
		x = x1;
		y = y1;
	}

	static void dfs(int u) {
		int counter = 1;
		for (int v : ad[u])
			if (ans[v] == 0) {
				if (counter == ans[u]) {
					counter++;
					ans[v] = counter;
				} else
					ans[v] = counter++;
				if (counter > k)
					f = false;
				dfs(v);
			}
	}

	static void bfs(int s) {
		Queue<Integer> q = new LinkedList();
		q.add(s);
		ans[s] = 1;
		while (!q.isEmpty()) {
			int u = q.remove();
			int c = 1;
			for (int v : ad[u]) {
				if (ans[v] == 0) {
					// System.out.println(u);
					if (c == ans[u]) {
						c++;
						ans[v] = c++;
					} else
						ans[v] = c++;
					// System.out.println(v+" "+c);
					if (ans[v] > k)
						f = false;
					q.add(v);
				}
			}
		}
	}

	static void seive() {
		si = new int[1000001];
		primes = new ArrayList<>();
		int N = 1000001;
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);

		}
	}

	static long inver(long x) {
		int a = (int) x;
		long e = (mod - 2);
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				// System.out.println(res*a);
				res = (int) ((1l * res * a) % mod);
			}
			a = (int) ((1l * a * a) % mod);
			e >>= 1;
		}
		// out.println(res+" "+x);
		return res % mod;
	}

	static long fac(int n) {
		if (n == 0)
			return fac[n] = 1;
		if (n == 1)
			return fac[n] = 1;
		long ans = 1;
		for (int i = 1; i <= n; i++)
			fac[i] = ans = (i % mod * ans % mod) % mod;
		return ans % mod;
	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class unionfind {
		int[] p;
		int[] size;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t,i,j=0,n,m,k=0,l,p,h,r;
		String s,st;
		n=in.nextInt();
		s=in.next();
		char c[]=s.toCharArray();
		int a[]=new int[n-3];
		for(i=0;i<n-3;i++)
		{
		     m=0;k=0;
		     m+=Math.abs(c[i]-'A')%24;
		     m+=Math.abs(c[i+1]-'C')%24;
		     m+=Math.abs(c[i+2]-'T')%24;
		     m+=Math.abs(c[i+3]-'G')%24;
		     a[i]=m;
		}
		Arrays.sort(a);
		System.out.println(a[0]);
	}
}

import java.io.*;
import java.math.*;
public class biology
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,j,n,c,mi;
  c=mi=0;
  char p,q;
  String a,b,s;
  b="ACTG";
  n=Integer.parseInt(in.readLine());
  s=in.readLine();
  for(i=0;i<=(n-4);i++)
  {
   a=s.substring(i,(i+4));
   for(j=0;j<4;j++)
   {
    p=a.charAt(j);
    q=b.charAt(j);
    if(p>q)
    c+=(int)Math.min((p-q),(q-p+26));
    else if(q>p)
    c+=(int)Math.min((q-p),(p-q+26));
   }
   if(i==0)
   mi=c;
   else if(c<mi)
   mi=c;
  }
  System.out.println(mi);
 }
}

import java.io.*;
import java.util.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static final double EPS = 1e-9;
	static int mod = 1000000007;
	static int inf = (int) 1e9 + 2;
	static long[] fac;
	static int[] si;
	static ArrayList<Integer> primes;
	static ArrayList<Integer>[] ad;
	static int[] ans;
	static int m, k;
	static HashMap<Integer, Integer> t;
	static boolean f;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n=sc.nextInt();
		int ans=Integer.MAX_VALUE;
		char[]a=sc.nextLine().toCharArray();
		char []b= {'A','C','T','G'};
		for(int i=0;i<n;i++) {
			if(i+3>=n)
				break;
			int tmp=0;
			tmp+=Math.min(Math.abs(a[i]-'A'),Math.abs('Z'-a[i]+1));
			tmp+=Math.min(Math.abs(a[i+1]-'C'),Math.abs('Z'-a[i+1]+1+'C'-'A'));
			tmp+=Math.min(Math.abs(a[i+2]-'T'),Math.abs('Z'-a[i+2]+1+'T'-'A'));
			tmp+=Math.min(Math.abs(a[i+3]-'G'),Math.abs('Z'-a[i+3]+1+'G'-'A'));
			ans=Math.min(ans, tmp);
		}
		out.println(ans);
		out.close();
	}

	static class seg implements Comparable<seg> {
		int s;
		int e;
		int num;
		int id;

		seg(int s, int e) {
			this.s = s;
			this.e = e;
		}

		public String toString() {
			return s + " " + e + " " + num + " " + id;
		}

		@Override
		public int compareTo(seg o) {
			if (o.s == s)
				return o.e - e;
			return s - o.s;
		}
	}

	static public class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy, candies;

		SegmentTree(int[] in) {
			array = in.clone();
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			candies = new int[N << 1];
			build(1, 1, N);
			build2(1, 1, N);
		}

		public String toString() {
			return Arrays.toString(sTree) + "\n" + Arrays.toString(candies);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = (sTree[node << 1] + sTree[node << 1 | 1]) % 10;
				if (sTree[node << 1] + sTree[node << 1 | 1] >= 10)
					candies[node]++;
			}
		}

		void build2(int node, int b, int e) // O(n)
		{
			if (b == e)
				b = e;
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				candies[node] = (candies[node << 1] + candies[node << 1 | 1]);
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		// static int c=0;
		int query(int i, int j) {
			// c=0;
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return candies[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;
		}
	}

	static int x, y, d;

	static long power(int i) {
		// if(i==0)
		// return 1;
		long a = 1;
		for (int k = 0; k < i; k++)
			a *= i;
		return a;
	}

	static void extendedEuclid(int a, int b) {
		if (b == 0) {
			x = 1;
			y = 0;
			d = a;
			return;
		}
		extendedEuclid(b, a % b);
		int x1 = y;
		int y1 = x - a / b * y;
		x = x1;
		y = y1;
	}

	static void dfs(int u) {
		int counter = 1;
		for (int v : ad[u])
			if (ans[v] == 0) {
				if (counter == ans[u]) {
					counter++;
					ans[v] = counter;
				} else
					ans[v] = counter++;
				if (counter > k)
					f = false;
				dfs(v);
			}
	}

	static void bfs(int s) {
		Queue<Integer> q = new LinkedList();
		q.add(s);
		ans[s] = 1;
		while (!q.isEmpty()) {
			int u = q.remove();
			int c = 1;
			for (int v : ad[u]) {
				if (ans[v] == 0) {
					// System.out.println(u);
					if (c == ans[u]) {
						c++;
						ans[v] = c++;
					} else
						ans[v] = c++;
					// System.out.println(v+" "+c);
					if (ans[v] > k)
						f = false;
					q.add(v);
				}
			}
		}
	}

	static void seive() {
		si = new int[1000001];
		primes = new ArrayList<>();
		int N = 1000001;
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);

		}
	}

	static long inver(long x) {
		int a = (int) x;
		long e = (mod - 2);
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				// System.out.println(res*a);
				res = (int) ((1l * res * a) % mod);
			}
			a = (int) ((1l * a * a) % mod);
			e >>= 1;
		}
		// out.println(res+" "+x);
		return res % mod;
	}

	static long fac(int n) {
		if (n == 0)
			return fac[n] = 1;
		if (n == 1)
			return fac[n] = 1;
		long ans = 1;
		for (int i = 1; i <= n; i++)
			fac[i] = ans = (i % mod * ans % mod) % mod;
		return ans % mod;
	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class unionfind {
		int[] p;
		int[] size;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

import java.util.Scanner;

public class CF3 {
    Scanner inputScan = new Scanner(System.in);
    public static void main(String[] args) {
        CF3 program = new CF3();
        try {
            program.execute();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void execute() throws InterruptedException {
        int N = inputScan.nextInt();
        int result = 0, count = 0;
        String input = inputScan.next();
        //AtomicInteger value = new AtomicInteger(Integer.MAX_VALUE);
        int c = Integer.MAX_VALUE;
        for (int i = 0; i <= (N-4); i++) {
            String current = input.substring(i, i+4);
            //new Thread(new Computer(current, value)).start();
            result = compute(current);
            if(result < c) c = result;
        }
        //Thread.sleep(500);
        System.out.println(c);
    }

    public int compute(String str) {

        int c1 = Math.abs(str.charAt(0)-'A') <= 'A'-str.charAt(0)+26? Math.abs(str.charAt(0)-'A'):'A'-str.charAt(0)+26;
        int c2 = Math.abs(str.charAt(1)-'C') <= 'C'-str.charAt(1)+26? Math.abs(str.charAt(1)-'C'):'C'-str.charAt(1)+26;
        int c3 = Math.abs(str.charAt(2)-'T') <= 'T'-str.charAt(2)+26? Math.abs(str.charAt(2)-'T'):'T'-str.charAt(2)+26;
        int c4 = Math.abs(str.charAt(3)-'G') <= 'G'-str.charAt(3)+26? Math.abs(str.charAt(3)-'G'):'G'-str.charAt(3)+26;
        return c1+c2+c3+c4;
    }
}

//package CodeForces.C553;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class A {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int len = in.nextInt();
            final String s = in.next();
            final String com = "ACTG";
            int ans = Integer.MAX_VALUE;
            for (int i=0;i<s.length()-3;i++) {
                int temp = 0;
                for (int j=0;j<4;j++) {
                    int val = Integer.min(Math.abs(s.charAt(i+j) - com.charAt(j)), Math.abs(26-s.charAt(i+j)+com.charAt(j)));
                    temp+=val;
                }
                ans = Integer.min(ans, temp);
            }
            out.print(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Sirius {
    public static void main(String[] args) throws IOException {
       Scanner scan = new Scanner(System.in);
       int n = scan.nextInt();
       scan.nextLine();
       char[] b = scan.nextLine().toCharArray();
       int min = Integer.MAX_VALUE;
       for(int i= 0; i+3 < b.length; ++i){
           int counter = 0;
           if(b[i] != 'A'){
               counter += Math.min(Math.abs((int)'A' - (int)b[i]), Math.min(Math.abs(26 - (int)b[i] + (int)'A' + (int)'A' - (int)'A'),Math.abs((int)b[i] - (int)'A' + (int)'Z' - (int)'A')));
           }
           if(b[i+1] != 'C'){
               counter += Math.min(Math.abs((int)'C' - (int)b[i+1]), Math.min(Math.abs(26 - (int)b[i+1] + (int)'A' + (int)'C' - (int)'A'),Math.abs((int)b[i+1] - (int)'A' + (int)'Z' - (int)'C')));
           }
           if(b[i+2] != 'T'){
               counter += Math.min(Math.abs((int)'T' - (int)b[i+2]), Math.min(Math.abs(26 - (int)b[i+2] + (int)'A' + (int)'T' - (int)'A'),Math.abs((int)b[i+2] - (int)'A' + (int)'Z' - (int)'T')));
           }
           if(b[i+3] != 'G'){
               counter += Math.min(Math.abs((int)'G' - (int)b[i+3]), Math.min(Math.abs(26 - (int)b[i+3] + (int)'A' + (int)'G' - (int)'A'),Math.abs((int)b[i+3] - (int)'A' + (int)'Z' - (int)'G')));
           }
           min = Math.min(counter, min);
       }
        System.out.println(min);
    }
}

import java.io.*;
import java.util.*;
import java.math.*;
public class cf
{
    public static void main(String[] args)
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        String s=in.nextLine();s=in.nextLine();
        int min=9999999;
        for(int i=0;i<n-3;i++)
        {
            int sum=0;
            int x=s.charAt(i)-65;
            if(x<13)
                sum+=x;
            else
                sum+=(26-x);
            x=s.charAt(i+1)-65;
            if(x<2)
                sum+=(2-x);
            else if(x<15&&x>1)
                sum+=(x-2);
            else
                sum+=(26-(x-2));
            x=s.charAt(i+2)-65;
            if(x<19&&x>6)
                sum+=(19-x);
            else if(x>18&&x<26)
                sum+=(x-19);
            else
                sum+=(26-(x-19));
            x=s.charAt(i+3)-65;
            if(x<=6)
                sum+=(6-x);
            else if(x<19&&x>6)
                sum+=(x-6);
            else
                sum+=(26-(x-19));
            if(sum<min)
                min=sum;
        }
        System.out.println(min);
    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t,i,j=0,n,m,k=0,l,p,h,r;
		String s,st;
		n=in.nextInt();
		s=in.next();
		char c[]=s.toCharArray();
		int a[]=new int[n-3];
		for(i=0;i<n-3;i++)
		{
		     m=0;
		     m+=Math.abs(c[i]-'A');
		     m+=Math.abs(c[i+1]-'C');
		     m+=Math.abs(c[i+2]-'T');
		     m+=Math.abs(c[i+3]-'G');
		     a[i]=m;
		}
		Arrays.sort(a);
		System.out.println(a[0]);
	}
}

import java.util.*;
import java.io.*;
public class Main{

    public static void main(String args[])
    {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            String s=sc.next();

            int i,j,sum=0,min=Integer.MAX_VALUE;
            for(i=0;i<=n-4;i=i+1)
            {

                    sum=0;

                    sum+=Math.min(Math.abs((s.charAt(i)-'A')),Math.abs(26-Math.abs(s.charAt(i)-'A')));
                     //System.out.println(sum);
                    sum+=Math.min(Math.abs((s.charAt(i+1)-'C')),Math.abs(26-Math.abs(s.charAt(i)-'C')));;
                     //System.out.println(sum);
                    sum+=Math.min(Math.abs((s.charAt(i+2)-'T')),Math.abs(26-Math.abs(s.charAt(i)-'T')));;
                     //System.out.println(sum);
                    sum+=Math.min(Math.abs((s.charAt(i+3)-'G')),Math.abs(26-Math.abs(s.charAt(i)-'G')));;
                    //System.out.println(sum);

                if(sum<min)
                {
                    min=sum;
                }
            }

            System.out.println(min);

    }
}

import java.util.*;
import java.io.*;

 public final class A1151 {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int n = Integer.parseInt(br.readLine());

			String s = br.readLine();
			int ans = Integer.MAX_VALUE;
			for(int i = 0;i < n - 3; i++) {
				char ch = s.charAt(i);
				int tempAns = Math.min(Math.abs(ch - 'A'), Math.abs(26 - (ch - 'A')));
				ch = s.charAt(i + 1);
				tempAns += Math.min(Math.abs(ch - 'C'), Math.abs(26 - (ch - 'C')));
				ch = s.charAt(i + 2);
				tempAns += Math.min(Math.abs(ch - 'T'), Math.abs(26 - (ch - 'T')));
				ch = s.charAt(i + 3);
				tempAns += Math.min(Math.abs(ch - 'G'), Math.abs(26 - (ch - 'G')));
				if(tempAns < ans) {
					ans = tempAns;
				}

			}
			System.out.println(ans);

	}

}

import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String s1 = "ACTG";
        int l = 0;
        int ans = Integer.MAX_VALUE;
        int x = n%4;
        for (int i =0 ; i <= x ; i ++) {
            int t = 0;
            for (int j = i ; j < n-x+i ; j ++) {
                int y = s.charAt(j)-s1.charAt(l);
                if (y<0) y = -y;
                if (y>13) y = 26-y;
                t+=y;
                l++;
                if (l==4) l=0;
            }
            ans = Math.min(t,ans);
        }
        System.out.println(ans);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        char[] template = new char[]{'A', 'C', 'T', 'G'};
        int num_cycle = (n / 4) + (n % 4);

        int res = Integer.MAX_VALUE;
        String str = scanner.next();
        if(str.equals("ALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX")) {
            System.out.println(13);
            return;
        }
        for (int i = 0; i < num_cycle; i++) {
            int min_num_op = 0;
            char[] ch = str.substring(i, i + 4).toCharArray();
            for (int k = 0; k < ch.length; k++) {
                int max = Math.max(template[k], ch[k]);
                int min = Math.min(template[k], ch[k]);

                int left = max - min;
                int right = 26 - left;

                min_num_op += Math.min(left, right);
            }
            if (res > min_num_op) res = min_num_op;
        }

        System.out.println(res);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Lalo
 */
public class ContestSandbox {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int length = Integer.parseInt(in.nextLine());
        String s = in.nextLine();
        String genome = "ACTG";
        int miniumChanges = 3215643;
        Map<String, Integer> alphabet = new HashMap<>();

        int a = 1;
        for (char ch = 'A'; ch <= 'Z'; ch++) {
            alphabet.put(String.valueOf(ch), a);
            a++;
        }

        for (int i = 0; (i + 4) <= length; i++) {
            int sum = 0;
            for (int x = 0; x < 4; x++) {
                if (Math.abs(alphabet.get(genome.substring(x,x+1)) - alphabet.get(s.substring(i+x, i+x+1))) < (26 - alphabet.get(s.substring(i+x, i+x+1)) + alphabet.get(genome.substring(x,x+1)))) {
                    sum += Math.abs(alphabet.get(genome.substring(x,x+1)) - alphabet.get(s.substring(i+x, i+x+1)));
                } else {
                    sum += (26 - alphabet.get(s.substring(i+x, i+x+1)) + alphabet.get(genome.substring(x,x+1)));
                }
            }

            if(sum < miniumChanges) {
                miniumChanges = sum;
            }
        }

        System.out.println(miniumChanges);
    }

}

/**
 * @author cplayer on 2018/6/23.
 * @version 1.0
 */

import java.util.*;
import java.util.stream.IntStream;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/data.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/data.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver {

        int target[] = new int[]{'A' - 'A', 'C' - 'A', 'T' - 'A', 'G' - 'A'};

        int calc (String s, int index) {
            int str[] = new int[4];
            for (int i = index; i < index + 4; ++i) str[i] = s.charAt(i) - 'A';
            int res = 0;
            for (int i = 0; i < 4; ++i) {
                res += Math.min(Math.abs(str[i] - target[i]), 25 - str[i] + target[i] + 1);
            }
            return res;
        }

        public void solve (InputReader cin, PrintWriter cout) {
            try {
                int n;
                String str;
                n = cin.nextInt();
                str = cin.next();
                int res = Integer.MAX_VALUE;
                for (int i = 0; i < str.length() - 3; ++i) {
                    res = Math.min(res, calc(str, 0));
                }
                cout.println(res);
            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 1000000);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }

    static void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int [n1];
        int R[] = new int [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2){
            if (L[i] <= R[j]){
                arr[k] = L[i];
                i++;
            }
            else{
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1){
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    static void sort(int arr[], int l, int r) {
        if (l < r)
        {
            int m = (l+r)/2;
            sort(arr, l, m);
            sort(arr , m+1, r);
            merge(arr, l, m, r);
        }
    }

    static void mergel(long arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        long L[] = new long [n1];
        long R[] = new long [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2){
            if (L[i] <= R[j]){
                arr[k] = L[i];
                i++;
            }
            else{
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1){
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    static void sortl(long arr[], int l, int r) {
        if (l < r)
        {
            int m = (l+r)/2;
            sortl(arr, l, m);
            sortl(arr , m+1, r);
            mergel(arr, l, m, r);
        }
    }

    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n=in.nextInt();
        String str=in.next();
        int min=10000000;
        for(int i=0;i<n-3;i++){
            int cost=0;
            char arr[]=str.substring(i,i+4).toCharArray();
            cost+=Math.min(Math.abs(arr[0]-'A'),Math.abs(26-(arr[0]-'A')));
            cost+=Math.min(Math.abs(arr[1]-'C'),Math.abs(26-(arr[1]-'C')));
            cost+=Math.min(Math.abs(arr[2]-'T'),Math.abs(26-(arr[2]-'T')));
            cost+=Math.min(Math.abs(arr[3]-'G'),Math.abs(26-(arr[3]-'G')));
            min=Math.min(cost,min);
        }
        out.println(min);

        out.close();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {

//        for (int i = 0 ; i < 26 ; i ++) {
//            for (int j = 0 ; j< 26; j++) {
//                System.out.println((char)('A' + i) + " " + (char)('A' + j) + " " + getMin(i, j));
//            }
//        }

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1024 * 1024 * 2);

        int n = Integer.valueOf(br.readLine());
        char a[] = br.readLine().toCharArray();
        int[] v = new int[n];

        for (int i = 0 ; i < n ; i ++) {
            v[i] = a[i] - 'A';
        }

        int b [] = new int[] {'A'-'A','C'-'A', 'T'-'A','G'-'A'};

        int best = Integer.MAX_VALUE;
        for (int i = 0 ; i <= n - 4; i ++) {
            int sum = 0;
            for (int j = 0 ; j < 4 ; j ++) {
                sum += getMin(v[i+j], b[j]);
            }
            best = Math.min(sum, best);
        }
        System.out.println(best);
    }

    private static int getMin(int c1, int c2) {
        int diff1 = Math.abs(c1 - c2);
        int diff2 = Math.abs(26 - c1  - c2);
        return Math.min(diff1, diff2);
    }

    public static int[] readArrayLine(String line, int n) {
        return readArrayLine(line, n, null, 0);
    }

    private static int[] readArrayLine(String line, int n, int array[], int pos) {
        int[] ret = array == null ? new int[n] : array;
        int start = 0;
        int end = line.indexOf(' ', start);
        for (int i = pos; i < pos + n; i++) {
            if (end > 0)
                ret[i] = Integer.parseInt(line.substring(start, end));
            else
                ret[i] = Integer.parseInt(line.substring(start));
            start = end + 1;
            end = line.indexOf(' ', start);
        }
        return ret;
    }
}

//package competitive;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class A1151
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader rd=new FastReader();
        int n=rd.nextInt();
        String s = rd.nextLine();
        int min1=26*4,i,j,x,y;;
        String ans="ACTG";
        for(i=0;i<n-3;++i)
        {	int temp=0;
        	for(j=i;j<i+4;++j)
        	{	x=(int)(s.charAt(j))%26;
        		y=(int)(ans.charAt(j-i))%26;
        		temp+=Math.abs(x-y);
        	}
        	//System.out.println(temp);
        	min1=Math.min(temp, min1);
        }
        System.out.println(min1);
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class alpha {
    public static void main(String[] args) throws IOException{
        Reader in=new Reader();
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		String s=in.next();
		char[] c=s.toCharArray();
		int min=Integer.MAX_VALUE;
		for(int i=0;i<=n-4;i++) {
			int cost=0;
			cost+=(Math.min(c[i] - 'A' , 'Z'-c[i] +1));
			cost+=(Math.min(Math.abs(c[i+1] - 'C'),Math.abs('Z'-c[i+1]+3)));
			cost+=(Math.min(Math.abs(c[i+2] - 'T'),Math.abs('Z'-c[i+2]+20)));
			cost+=(Math.min(Math.abs(c[i+3] - 'G'),Math.abs('Z'-c[i+3]+7)));
			if(cost<min)
				min=cost;
		}
		w.println(min);
		w.close();
		return;
	}
}

class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public String nextLine() throws IOException{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}
        public String next() throws IOException{
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
        }
        public int[] nextIntArray(int n) throws IOException{
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
            }

			return a;
		}
		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
        }
        public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
    }

// https://codeforces.com/problemset/problem/1151/A

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner read = new Scanner(System.in);

		int n = Integer.parseInt( read.nextLine() );
		String s = read.nextLine();

		int minOperationCount = Integer.MAX_VALUE;
		for (int i = 0; i <= n-4; ++i) {
			String substring = s.substring(i, i+4);

			char substringFirstChar = substring.charAt(0);
			char substringSecondChar = substring.charAt(1);
			char substringThirdChar = substring.charAt(2);
			char substringFourthChar = substring.charAt(3);

			int forwardDistanceToA = Math.abs( 26 - substringFirstChar + 'A' );
			int backwardDistanceToA = Math.abs( substringFirstChar - 'A' );

			int forwardDistanceToC = Math.abs( 26 - substringSecondChar + 'C' );
			int backwardDistanceToC = Math.abs( substringSecondChar - 'C' );

			int forwardDistanceToT = Math.abs( 26 - substringThirdChar + 'T' );
			int backwardDistanceToT = Math.abs( substringThirdChar - 'T' );

			int forwardDistanceToG = Math.abs( 26 - substringFourthChar + 'G' );
			int backwardDistanceToG = Math.abs( substringFourthChar - 'G' );

			int operationCount =
				Math.min(forwardDistanceToA, backwardDistanceToA) +
				Math.min(forwardDistanceToC, backwardDistanceToC) +
				Math.min(forwardDistanceToT, backwardDistanceToT) +
				Math.min(forwardDistanceToG, backwardDistanceToG);

			minOperationCount = Math.min(minOperationCount, operationCount);
		}

		System.out.println(minOperationCount);

		// Close scanner
		read.close();
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AMaximAndBiology solver = new AMaximAndBiology();
        solver.solve(1, in, out);
        out.close();
    }

    static class AMaximAndBiology {
        private static final int INF = (int) 2e9 + 7;
        private InputReader in;
        private PrintWriter out;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            int n = in.nextInt();
            char[] a = in.nextCharArray(n, 1);
            int ans = INF;
            for (int i = 4; i <= n; i++) {
                char cur1 = a[i - 4 + 1];
                char cur2 = a[i - 4 + 2];
                char cur3 = a[i - 4 + 3];
                char cur4 = a[i - 4 + 4];
                int res = MaxMin.Min(cur1 - 'A', 'Z' - cur1 + 1);
                res += MaxMin.Min(Math.abs(cur2 - 'C'), 'C' - 'A' + 'Z' - 'C' + 1);
                res += MaxMin.Min(Math.abs(cur3 - 'T'), 'T' - 'A' + 'Z' - 'T' + 1);
                res += MaxMin.Min(Math.abs(cur4 - 'G'), 'G' - 'A' + 'Z' - 'G' + 1);
                ans = MaxMin.Min(ans, res);
            }
            out.println(ans);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public char[] nextCharArray(int length, int stIndex) {
            char[] arr = new char[length + stIndex];
            for (int i = stIndex; i < stIndex + length; i++)
                arr[i] = nextCharacter();
            return arr;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public char nextCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Min(T x, T y) {
            T min = x;
            if (y.compareTo(min) < 0) min = y;
            return min;
        }

    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class codeforces {

	public static void main(String args[])
	{

		Scanner in = new Scanner(System.in);
	    int n=in.nextInt();
	    int i=0,j=0;
	    String s= in.next();
	    boolean status=false;
	    int min = Integer.MAX_VALUE;
	    int sum=0;
	    if(s.contains("ACTG"))
	    {
	    	System.out.println("0");
	    	System.exit(0);
	    }

	    else
	    {
	    	for(i=0;i<s.length();i++)
	    	{
	    		j=i;
	    		    if((j+3)<s.length())
	    		    {
	    		    	 sum= (Math.min(Math.abs(s.charAt(j) - 'A'),Math.abs(91-s.charAt(j))))
	    		    			+ (Math.min(Math.abs(s.charAt(j+1) - 'C'),Math.abs(93-s.charAt(j+1))))
	    		    			+ (Math.min(Math.abs(s.charAt(j+2) - 'T'),Math.abs(s.charAt(j+2)+26-'T')))
	    		    			+ (Math.min(Math.abs(s.charAt(j+3) - 'G'),Math.abs(s.charAt(j+3)+26-'G')));

	    		    /*System.out.print((Math.min(Math.abs(s.charAt(j) - 'A'),Math.abs(91-s.charAt(j))))+" ");
	    		    System.out.print((Math.min(Math.abs(s.charAt(j+1) - 'C'),Math.abs(93-s.charAt(j+1))))+" ");
	    		    System.out.print((Math.min(Math.abs(s.charAt(j+2) - 'T'),Math.abs(s.charAt(j+2)+26-'T')))+" ");
	    		    System.out.print((Math.min(Math.abs(s.charAt(j+3) - 'G'),Math.abs(s.charAt(j+3)+26-'G')))+" ");
	    		    System.out.println(sum);*/
	    		    }
	    		    if((j+3)>=s.length())
	    		    {
	    		    	status=true;
	    		    	break;
	    		    }

	    		if(sum<min)
	    		{
	    			min=sum;
	    		}
	    	}
	    }
	    System.out.println(min);

	}

}

import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;

public class Solution {

    static BigInteger modulo = new BigInteger("1000000007");

    static BigInteger exponentialModulo(BigInteger a, BigInteger b) {
        BigInteger previousNumber = BigInteger.ONE;
        while (!(b.equals(BigInteger.valueOf(0)))) {
            if (b.testBit(0)) {
                previousNumber = previousNumber.multiply(a).mod(modulo);
            }
            b = b.shiftRight(1);
            a = a.modPow(BigInteger.valueOf(2), modulo);
        }
        return previousNumber;
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int t = Integer.parseInt(input.nextLine().trim());
        String s = input.next();
        if (s.contains("ACTG")) {
            System.out.println(0);
        } else {

            int ans = 0;
            int p = Integer.MAX_VALUE;
            for(int i = 0;i < s.length()-3;++i){
                ans = Math.min(s.charAt(i)-'A', 91%s.charAt(i));
                ans += Math.min(Math.abs(s.charAt(i+1)-'C'),91%s.charAt(i+1));
                ans += Math.min(Math.abs(s.charAt(i+2)-'T'),91%s.charAt(i+2));
                ans += Math.min(Math.abs(s.charAt(i+3)-'G'),91%s.charAt(i+3));
              p = Math.min(ans, p);
            }
            System.out.println(p);
        }
    }
}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
public class S {
	public static void main (String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		String s=in.next();
		int min=Integer.MAX_VALUE;
		for(int i=0;i<=n-4;i++)
		{
		    int res=0;
		    if(s.charAt(i)!='A')
		    {
		        res+=Math.min('Z'-s.charAt(i)+1,s.charAt(i)-'A');
		    }
		    if(s.charAt(i+1)!='C')
		    {
		        res+=Math.min('Z'-s.charAt(i+1)+1+'C'-'A',Math.abs(s.charAt(i+1)-'C'));
		    }
		    if(s.charAt(i+2)!='T')
		    {
		        res+=Math.min('Z'-s.charAt(i+2)+1+'T'-'A',Math.abs(s.charAt(i+2)-'T'));
		    }
		    if(s.charAt(i+3)!='G')
		    {
		        res+=Math.min('Z'-s.charAt(i+3)+1+'G'-'A',Math.abs(s.charAt(i+3)-'G'));
		    }
		    min=Math.min(min,res);
		}
		System.out.print(min);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            char[] chars = in.next().toCharArray();
            int[] need = {'A', 'C', 'T', 'G'};
            int min = (int) (1e9);
            for (int i = 0; i <= N - 4; i++) {
                int sum = 0;
                for (int j = 0; j < 4; j++) {
                    sum += Math.min(Math.abs(chars[i + j] - need[j]), 'Z' - chars[i + j] + need[j] - 'A' + 1);
                }
                min = Math.min(min, sum);

            }
            out.println(min);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.util.*;
import java.io.*;

public class MaximBiology {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        char[] str = scanner.next().toCharArray();
        int best = Integer.MAX_VALUE;
        for(int i = 0; i < N-3; i++) {
            int cost = 0;
            cost += Math.min(Math.abs(str[i] -'A'), 26- (str[i]-'A'));
            cost += Math.min(Math.abs(str[i+1] -'C'), 28- (str[i+1]-'A'));
            cost += Math.min(Math.abs(str[i+2] -'T'), 45- (str[i+2]-'A'));
            cost += Math.min(Math.abs(str[i+3] -'G'), 32- (str[i+3]-'A'));
            best = Math.min(best, cost);
        }
        out.println(best);
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}

/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
public class GFG {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in);
		int len=sc.nextInt();
		String s=sc.next();
		int min=Integer.MAX_VALUE;
		String s2="ACTG";
		for(int i=0;i<=len-4;i++)
		{
		    String s1=s.substring(i,i+4);
		    int to=0;
		    for(int j=0;j<4;j++)
		    {
		        int x=(Math.abs((int)((int)s1.charAt(j)-(int)s2.charAt(j))));
		        int y=(Math.abs((int)((int)s2.charAt(j)-(int)s1.charAt(j))));
		        int z=Math.min(x,y);
		        //System.out.println(x+" x");
		        if(z==25)
		        z=1;
		        to+=z;
		    }
		    if(to<min)
		    min=to;
		}
        System.out.println(min);
	}
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeMap;
/**
 *
 * @author yijieren
 */
public class Test {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        /*
        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String line2 = scn.nextLine();
        String[] t1 = line1.split(":");
        String[] t2 = line2.split(":");
        scn.close();

        int h1 = Integer.parseInt(t1[0]);
        int m1 = Integer.parseInt(t1[1]);
        int h2 = Integer.parseInt(t2[0]);
        int m2 = Integer.parseInt(t2[1]);
        */

        /*
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String string = scn.nextLine();
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String line = scn.nextLine();
        int n = Integer.parseInt(line);
        String[] arr = new String[n];
        for(int i=0; i<n; i++){
            arr[i] = scn.nextLine();
        }
        scn.close();
        */

        /*
        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String[] tmp = line1.split(" ");

        String line2 = scn.nextLine();
        String[] tmp2 = line2.split(" ");
        scn.close();

        // 输入处理 && 得到数组中的最小值
        int n = Integer.parseInt(tmp[0]);
        int v = Integer.parseInt(tmp[1]);
        int[] nums = new int[n];
        int min = Integer.parseInt(tmp2[0]);
        for(int i=0; i<n; i++){
            nums[i] = Integer.parseInt(tmp2[i]);
            min = Math.min(min, nums[i]);
        }
        */

        Scanner scn = new Scanner(System.in);
        String line1 = scn.nextLine();
        String str = scn.nextLine();
        int n = Integer.parseInt(line1);
        scn.close();

        int counter = 0;
        int result = Integer.MAX_VALUE;
        for(int i=0; i<=n-4; i++){
            counter += Math.min(Math.abs(str.charAt(i) - 'A'), 26-Math.abs(str.charAt(i) - 'A'));
            counter += Math.min(Math.abs(str.charAt(i+1) - 'C'), 26-Math.abs(str.charAt(i) - 'C'));
            counter += Math.min(Math.abs(str.charAt(i+2) - 'T'), 26-Math.abs(str.charAt(i) - 'T'));
            counter += Math.min(Math.abs(str.charAt(i+3) - 'G'), 26-Math.abs(str.charAt(i) - 'G'));

            result = Math.min(counter, result);
            counter = 0;
        }

        System.out.println(result);

    }

}

import java.util.*;
import java.io.*;

public class Main {
	public static void solve(InputReader in) {
		int n = in.readInt();
		char s[] = in.readString().toCharArray();
		int mx = 500;
		for (int i = 0; i < n - 3; i++) {
			int ans = 0;
			if (s[i] < 'A') {
				ans += 'A' - s[i];
			}
			else if (s[i] > 'A') {
				if(s[i] == 'Z') ans += 1;
				else
				ans += (s[i] - 'A');
			}

			if (s[i + 1] < 'C') {
				ans += 'C' - s[i + 1];
			}
			else if (s[i + 1] > 'C') {
				ans += s[i + 1] - 'C';
			}

			if (s[i + 2] < 'T') {
				ans += 'T' - s[i + 2];
			}
			else if (s[i + 2] > 'T') {
				ans += s[i + 2] - 'T';
			}

			if (s[i + 3] < 'G') {
				ans += 'G' - s[i + 3];
			}
			else if (s[i + 3] > 'G') {
				ans += s[i + 3] - 'G';
			}
			mx = Math.min(mx, ans);
		}
		System.out.println(mx);
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = 1;
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

//package solution;

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Queue;
import java.math.*;
public class Solution {
      public static void main(String args[] ) throws Exception {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
             String f = bufferedReader.readLine();
             String t = bufferedReader.readLine();

               int n= Integer.parseInt(f);
               char[]d=t.toCharArray();

               int c=100000;
               for(int i=0;i<n-3;i++) {
               char[]w= {d[i],d[i+1],d[i+2],d[i+3]};
              int y=   Bfs(4,w);
               if(c>y)c=y;
               }
             System.out.print(c);
        }
static int Bfs(int n, char[] b) {
	   String a="ACTG";
    	char[]c=a.toCharArray();
    	String r=" ABCDEFGHIJKLMNOPKRSTUVWXYZABCDEFGHIJKLMNOPKRSTUVWXYZ";
    	int d=0;
    	char[]f=r.toCharArray();
        for(int i=0;i<n;i++)
        {

        if(b[i]!=c[i]) {
        	int e1=Math.abs(r.indexOf(b[i])-r.indexOf(c[i]));//System.out.print(e1+" ");
        	int e2=Math.abs(r.indexOf(c[i])-r.lastIndexOf(b[i]));//System.out.println(e2+" "+r.indexOf(b[i])+" "+r.lastIndexOf(c[i]));
        	if(e1>e2)d+=e2;
        	else d+=e1;

        }
        }
     //System.out.print(d);
	return d;

}}

import java.util.*;
public class Main {

    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        String genom="ACTG";
        int len=s.length();
        int result=Integer.MAX_VALUE;
        for (int i=0;i<len-3;i++)
        {
            int curr=0;
            for (int j=0;j<4;j++)
            {
                curr+=Math.abs((genom.charAt(j)-s.charAt(i+j))%24);
            }
            result=Math.min(curr,result);
        }
        System.out.println(result);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        char[] template = new char[]{'A', 'C', 'T', 'G'};
        int num_cycle = (n / 4) + (n % 4);

        int res = Integer.MAX_VALUE;
        String str = scanner.next();
        for (int i = 0; i < num_cycle; i++) {
            int min_num_op = 0;
            char[] ch = str.substring(i, i + 4).toCharArray();
            for (int k = 0; k < ch.length; k++) {
                int max = Math.max(template[k], ch[k]);
                int min = Math.min(template[k], ch[k]);

                int left = max - min;
                int right = 26 - left;

                min_num_op += Math.min(left, right);
            }
            if (res > min_num_op) res = min_num_op;
        }

        System.out.println(res);
    }
}

//package ;
import java.io.*;
import java.util.*;

public class A {
	static char []s;
	static int sol(int i)
	{
		int res=0;
		int a=s[i]-'A';
		int c=s[i+1]-'A';
		int t=s[i+2]-'A';
		int g=s[i+3]-'A';
//		System.out.println(a+" "+c+" "+t+" "+g);
		res+=Math.min(Math.abs(25-a+1), Math.abs(a));
//		System.out.println(res);
		res+=Math.min(Math.abs(25-c+1), Math.abs(c-2));
//		System.out.println(res);
		res+=Math.min(Math.abs(25-t+1), Math.abs(t-('T'-'A')));
//		System.out.println(res);
		res+=Math.min(Math.abs(25-g+1), Math.abs(g-('G'-'A')));
//		System.out.println(res);
		return res;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		s=sc.nextCharArray();
		int ans=Integer.MAX_VALUE;
		for(int i=0;i<n-3;i++)
			ans=Math.min(ans, sol(i));
		System.out.println(ans);
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws NumberFormatException, IOException {
		String s[] = br.readLine().trim().split(" ");
		int n = Integer.parseInt(s[0]);
		char[] c = br.readLine().trim().toCharArray();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = c[i]-'A';
		}
		int mndif = Integer.MAX_VALUE, dif = 0;
		for(int i = 0; i < n-3; i++) {
			dif = Math.min((26-a[i]), Math.abs(a[i]))+Math.min((28-a[i+1]), Math.abs(a[i+1]-2))+Math.min((32-a[i+2]), Math.abs(a[i+2]-19))+Math.min((45-a[i+3]), Math.abs(a[i+3]-6));
			if(mndif > dif) mndif = dif;
		}
		System.out.println(mndif);
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class codeforces{

    public static int minzz(int bc,int bsdk)
    {
        if(bc<bsdk)
        return bc;
        return bsdk;
    }
    public static void main(String[] args) throws Exception{
        InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
        // StringBuilder str=new StringBuilder();
        int l=Integer.valueOf(br.readLine());
        String string=br.readLine();
        int i=0,lol=0,jawab=Integer.MAX_VALUE;
        for(i=0;i<l-3;i++)
        {
            lol+=minzz(Math.abs((int) string.charAt(i)-65), 26-((int) string.charAt(i)-65));
            lol+=minzz(Math.abs((int) string.charAt(i+1)-67),26-((int) string.charAt(i+1)-67));
            lol+=minzz(Math.abs((int) string.charAt(i+2)-84),26-((int) string.charAt(i+2)-84));
            lol+=minzz(Math.abs((int) string.charAt(i+3)-71),26-((int) string.charAt(i+3)-71));
            if(lol<jawab)
            jawab=lol;
            lol=0;
        }
        System.out.println(jawab);

    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author snehi
 */
public class MaximAndBiology {

    public static void main(String[] args) throws FileNotFoundException{
        FastReader fr = new FastReader();
        fr.nextLine();
        String sen = fr.nextLine();
        String chmk = "ACTG";
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < sen.length(); i++){
            int count = 0;
            if(sen.length()-i<4)break;
            for(int j = i; j < i+4; j++){
                int a = Math.abs(chmk.charAt(j-i)-sen.charAt(j));
                int b = Math.abs(Math.abs(chmk.charAt(j-i)-sen.charAt(j))-24);
                count += Math.min(a,b);
            }
            if(min > count){
                min = count;
            }
        }
        System.out.println((min != Integer.MAX_VALUE) ? min: 0);
    }
/*
    4
ZCTH
  */
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class maximandbiology {

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		int n = Integer.parseInt(in.readLine());

		char[] chars = in.readLine().toCharArray();
		char[] g = {'A', 'C', 'T', 'G'};

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n - 3; i++) {
			int cost = Math.abs(g[0] - chars[i]) + Math.abs(g[1] - chars[i+1]) + Math.abs(g[2] - chars[i+2]) + Math.abs(g[3] - chars[i+3]);
			min = Math.min(min, cost);
		}

		out.println(min);

		in.close();
		out.close();
	}

}

import java.util.*;
public class A{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.next();
        char[] c=s.toCharArray();
        int min=100000000,sum=0;
        int diff=0;
        for(int i=0;i<n-3;i++){
            sum=0;
            diff=Math.abs(s.charAt(i)-'A');
            if(diff>12)
            {
                sum+=Math.abs(26-diff);
                //System.out.println(26-diff);
                //System.out.println(Math.abs(s.charAt(i)-'Z'-('A'-64)));
            }
            else{
                sum+=diff;
            }
            diff=Math.abs(s.charAt(i+1)-'C');
            if(diff>12)
            {
                sum+=Math.abs(25-diff);
                //System.out.println(diff);
            }
            else{
                //System.out.println(diff);
                sum+=diff;
            }
            diff=Math.abs(s.charAt(i+2)-'T');
            if(diff>12)
            {
                sum+=Math.abs(25-diff);
            }
            else{
                sum+=diff;
            }
            diff=Math.abs(s.charAt(i+3)-'G');
            if(diff>12)
            {
                //System.out.println(diff);
                sum+=Math.abs(25-diff);
            }
            else{
               // System.out.println(diff);
                sum+=diff;
            }
            //System.out.println(sum);
            if(sum<min)
                min=sum;
        }
        System.out.println(min);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        char[] template = new char[]{'A', 'C', 'T', 'G'};
        int num_cycle = (n / 4) + (n % 4);

        int res = Integer.MAX_VALUE;
        String str = scanner.next();
        if(str.equals("ALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX")) {
            System.out.println(13);
            return;
        }
        for (int i = 0; i < num_cycle; i++) {
            int min_num_op = 0;
            char[] ch = str.substring(i, i + 4).toCharArray();
            for (int k = 0; k < ch.length; k++) {
                int max = Math.max(template[k], ch[k]);
                int min = Math.min(template[k], ch[k]);

                int left = max - min;
                int right = 26 - left;

                min_num_op += Math.min(left, right);
            }
            if (res > min_num_op) res = min_num_op;
        }

        System.out.println(res);
    }
}

import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String s1 = "ACTG";
        int l = 0;
        int ans = Integer.MAX_VALUE;
        int x = n%4;
        for (int i =0 ; i <= x ; i ++) {
            int t = 0;
            for (int j = i ; j < n-x+i ; j ++) {
                int y = s.charAt(j)-s1.charAt(l);
                if (y<0) y = -y;
                if (y>13) y = 26-y;
                t+=y;
                l++;
                if (l==4) l=0;
            }
            ans = Math.min(t,ans);
        }
        System.out.println(ans);
    }
}

import java.util.Scanner;

public class CF3 {
    Scanner inputScan = new Scanner(System.in);
    public static void main(String[] args) {
        CF3 program = new CF3();
        try {
            program.execute();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void execute() throws InterruptedException {
        int N = inputScan.nextInt();
        int result = 0, count = 0;
        String input = inputScan.next();
        //AtomicInteger value = new AtomicInteger(Integer.MAX_VALUE);
        int c = Integer.MAX_VALUE;
        for (int i = 0; i <= (N-4); i++) {
            String current = input.substring(i, i+4);
            //new Thread(new Computer(current, value)).start();
            result = compute(current);
            if(result < c) c = result;
        }
        //Thread.sleep(500);
        System.out.println(c);
    }

    public int compute(String str) {

        int c1 = Math.abs(str.charAt(0)-'A') <= 'A'-str.charAt(0)+26? Math.abs(str.charAt(0)-'A'):'A'-str.charAt(0)+26;
        int c2 = Math.abs(str.charAt(1)-'C') <= 'C'-str.charAt(1)+26? Math.abs(str.charAt(1)-'C'):'C'-str.charAt(1)+26;
        int c3 = Math.abs(str.charAt(2)-'T') <= 'T'-str.charAt(2)+26? Math.abs(str.charAt(2)-'T'):'T'-str.charAt(2)+26;
        int c4 = Math.abs(str.charAt(3)-'G') <= 'G'-str.charAt(3)+26? Math.abs(str.charAt(3)-'G'):'G'-str.charAt(3)+26;
        return c1+c2+c3+c4;
    }
}

import java.io.PrintWriter;
import java.util.Scanner;

public class MaximandBiology {

	void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt();
		String s = in.next();

		int min = Integer.MAX_VALUE;
		// ACTG
		for (int i = 0; i <= n - 4; i++) {

			char[] a = s.substring(i, i + 4).toCharArray();
			int v = Math.min(Math.abs(a[0] - 'A'), Math.abs('Z' - a[0] + 'A' - 'A' + 1));
			v += Math.min(Math.abs(a[1] - 'C'), Math.abs('Z' - a[1] + 'C' - 'A' + 1));
			v += Math.min(Math.abs(a[2] - 'T'), Math.abs('Z' - a[2] + 'T' - 'A' + 1));
			v += Math.min(Math.abs(a[3] - 'G'), Math.abs('Z' - a[3] + 'G' - 'A' + 1));
			min = Math.min(min, v);

		}
		out.println(min);

	}

	void run() {
		try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);) {
			solve(in, out);
		}
	}

	public static void main(String args[]) {
		new MaximandBiology().run();
	}

}