President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.

The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. 

Input

The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.

Output

Print the only number — the amount of President's deputies.

Examples

Input

3 4 R
G.B.
.RR.
TTT.


Output

2


Input

3 3 Z
...
.H.
..Z


Output

0
import java.io.*;
import java.util.InputMismatchException;
import java.util.Arrays;

public class Main {
    static InputStream inStream;
    static PrintWriter out = new PrintWriter(System.out);
    static String INPUT = "";

    public static int deputyNum=0;
    public static char prevColor = '.';
    public static int top=-1, right=-1, left=-1, bottom=-1;
    public static char[][] office;

    public static void testT(){
        for(int i=left; i<=right; i++) {
            char curChar = office[top - 1][i];
            if (curChar != prevColor && curChar != '.'){
                deputyNum++;
                prevColor = curChar;
            }
        }
    }

    public static void testR(){
        for(int i=top; i<=bottom; i++) {
            char curChar = office[i][right+1];
            if (curChar != prevColor && curChar != '.'){
                deputyNum++;
                prevColor = curChar;
            }
        }
    }

    public static void testB(){
        for(int i=right; i>=left; i--) {
            char curChar = office[bottom+1][i];
            if (curChar != prevColor && curChar != '.'){
                deputyNum++;
                prevColor = curChar;
            }
        }
    }

    public static void testL(){
        for(int i=bottom; i>=top; i--) {
            char curChar = office[i][left-1];
            if (curChar != prevColor && curChar != '.'){
                deputyNum++;
                prevColor = curChar;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        inStream = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        int n = nextInt();
        int m = nextInt();
        boolean deskFound = false;
        char pc = nextChar();


        office = new char[n][m];
        StringBuilder row;

        for(int curRow=0; curRow<n; curRow++){
            row = nextStringBuilder();
            deskFound = false;

            for(int curCol=0; curCol<m; curCol++){
                office[curRow][curCol] = row.charAt(curCol);
                if(office[curRow][curCol]==pc) {
                    deskFound = true;
                    if (top == -1) {
                        top = curRow;
                        left = curCol;
                        //move until we hit end of desk
                        while (office[curRow][curCol] == pc && curCol < m-1) {
                            curCol++;
                            office[curRow][curCol] = row.charAt(curCol);
                        }
                        if(office[curRow][curCol]==pc)
                            right = curCol;
                        else
                            right = curCol-1;
                    }
                }
            }
            //if we have found top and then had row without desk
            if(top!=-1 && bottom==-1 && deskFound==false)
                bottom = curRow - 1;
        }

        if(bottom==-1)bottom=n-1;
        if(top>0)
            testT();
        if(right<m-1)
            testR();
        if(bottom<n-1)
            testB();
        if(left>0)
            testL();

        out.println(deputyNum);
        out.flush();
    }






    private static boolean eof() {
        if (lenbuf == -1) return true;
        int lptr = ptrbuf;
        while (lptr < lenbuf) if (!isSpaceChar(inbuf[lptr++])) return false;
        try {
            inStream.mark(1000);
            while (true) {
                int b = inStream.read();
                if (b == -1) {
                    inStream.reset();
                    return true;
                } else if (!isSpaceChar(b)) {
                    inStream.reset();
                    return false;
                }
            }
        } catch (IOException e) {
            return true;
        }
    }

    private static byte[] inbuf = new byte[1024];
    static int lenbuf = 0, ptrbuf = 0;

    private static int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = inStream.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0)
                return -1;
        }
        return inbuf[ptrbuf++];
    }

    private static boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private static int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private static double nextDouble() {
        return Double.parseDouble(nextString());
    }

    private static char nextChar() {
        return (char) skip();
    }

    private static String nextString() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private static StringBuilder nextStringBuilder() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb;
    }

    private static char[] nextString(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private static char[][] nextMap(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++)
            map[i] = nextString(m);
        return map;
    }

    private static int[] nextArray0(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    private static int[] nextArray1(int n) {
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++)
            a[i] = nextInt();
        return a;
    }

    private static long[] nextArrayLong1(int n) {
        long[] a = new long[n + 1];
        for (int i = 1; i <= n; i++)
            a[i] = nextLong();
        return a;
    }

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

    private static int nextInt() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static long nextLong() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
}
