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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Hashtable;


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");
        
        int height = Integer.parseInt(input[0]);
        int width = Integer.parseInt(input[1]);
        char color = input[2].charAt(0);
        
        char[][] room = new char[height][width];
        
        Hashtable<Character, Integer> matches = new Hashtable<Character, Integer>();
        
        
        for (int row = 0; row < height; row++) {
            char[] rowString = br.readLine().toCharArray(); 
            for (int col = 0; col < width; col++) {
                room[row][col] = rowString[col];
            }
        }
        
        for (int row = 0; row < height; row++) {
            
            for (int col = 0; col < width; col++) {
                
                // Only check around if we are on the presidents desk
                if (room[row][col] == color) {
                    
                    // we have just a row
                    if (height == 1 && width > 1) {
                        // Check right and left, until one to the end
                        if (col+1 < width) {
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                        }
                        if (col > 0) {
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                        }
                    }
                    
                    // we have just a column
                    if (height > 1 && width == 1) {
                        // Check up and down, until one to the bottom
                        if (row+1 < height) {
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                        }
                        if (row > 0) {
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                        }
                    }
                    
                    // If we have anything bigger than a 2 x 2:
                    if (height > 1 && width > 1) {
                        
                        // top left: check down and right
                        if (col==0 && row==0) {
                            // System.out.print(room[row][col] + " top left ");
                            // row+1: down
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                            // col+1: right
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                        // top right: check left and down
                        } else if (row==0 && col==width-1) {
                            // System.out.print(room[row][col] + " top right ");
                            // col-1: left
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                            // row+1: down
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                        // bottom left: check up and right
                        } else if (row==height-1 && col==0) {
                            // System.out.print(room[row][col] + " bottom left ");
                            // row-1: up
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                            // col+1: right
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                        // bottom right: check up and left  
                        } else if (row==height-1 && col==width-1) {
                            // System.out.print(room[row][col] + " bottom right ");
                            // row-1: up
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                            // col-1: left
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                        // top row: check left right and down
                        } else if (row==0) {
                            // System.out.print(room[row][col] + " top row ");
                            // row+1: down
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                            // col-1: left
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                            // col+1: right
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                        // bottom row: check up left and right  
                        } else if (row==height-1) {
                            // System.out.print(room[row][col] + " bottom row ");
                            // row-1: up
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                            // col-1: left
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                            // col+1: right
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                        // first column: up right and down
                        } else if (col==0) {
                            // System.out.print(room[row][col] + " first column ");
                            // row+1: down
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                            // col+1: right
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                            // row-1: up
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                        // far column: up down and left
                        } else if (col==width-1) {
                            // System.out.print(room[row][col] + " last column ");
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                            // col-1: left
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                        // in the middle: check everywhere
                        } else {
                            // System.out.print(room[row][col] + " middle ");
                            if (room[row+1][col] != '.') {
                                if (!matches.containsKey(room[row+1][col])) {
                                    if (room[row+1][col] != color) {
                                        matches.put(room[row+1][col], 1);
                                    }
                                }
                            }
                            if (room[row][col-1] != '.') {
                                if (!matches.containsKey(room[row][col-1])) {
                                    if (room[row][col-1] != color) {
                                        matches.put(room[row][col-1], 1);
                                    }
                                }
                            }
                            if (room[row-1][col] != '.') {
                                if (!matches.containsKey(room[row-1][col])) {
                                    if (room[row-1][col] != color) {
                                        matches.put(room[row-1][col], 1);
                                    }
                                }
                            }
                            if (room[row][col+1] != '.') {
                                if (!matches.containsKey(room[row][col+1])) {
                                    if (room[row][col+1] != color) {
                                        matches.put(room[row][col+1], 1);
                                    }
                                }
                            }
                        }
                    } // 2 x 2 check
                } // End president check
            }
            
            // System.out.println("");
        }
        
        
        // System.out.println(matches);
        System.out.println(matches.size());
        

    }

}
