// The "Solution4" class.
import java.awt.*;
import java.io.*;


public class question5
{

    public static void main (String[] args) throws IOException, NumberFormatException

    {

	BufferedReader input = new BufferedReader (new FileReader ("DATA5.txt"));

	PrintWriter output = new PrintWriter (new FileWriter ("OUT5.txt"));

	String input1 = input.readLine ();
	int row = Integer.parseInt (input1);

	String input2 = input.readLine ();
	int colume = Integer.parseInt (input2);
	String[] line2 = new String [row];
	for (int i = 0 ; i < row ; i++)
	{
	    line2 [i] = input.readLine ();
	} //get lines

	char[] [] line = new char [row] [colume];
	for (int x = 0 ; x < row ; x++)
	    for (int y = 0 ; y < colume ; y++)
	    {
		line [x] [y] = line2 [x].charAt (y);
	    }



	boolean[] [] boo = new boolean [row] [colume];
	boolean valid = false; //true if got new


	for (int i2 = 1 ; i2 <= 5 ; i2++)
	{
	    boolean boo4 = false;
	    int counter = 0;
	    String tempStr;
	    int room = 1;
	    for (int x = 0 ; x < row ; x++)
		for (int y = 0 ; y < colume ; y++)
		    boo [x] [y] = false;
	    //end initialization
	    tempStr = " " + i2;
	    for (int x = 0 ; x < row ; x++)
		for (int y = 0 ; y < colume ; y++)
		{
		    if (line [x] [y] == tempStr.charAt (1))
		    {
			boo [x] [y] = true;
			counter++;
		    }
		}
	    //end of finding the number

	    do
	    {

		valid = false;
		for (int x = 0 ; x < row ; x++)
		    for (int y = 0 ; y < colume ; y++)
		    {
			if (line [x] [y] == '.' && boo [x] [y] == false && Close (x, y, row, colume, boo))
			{
			    boo [x] [y] = true;
			    valid = true;
			    counter++;
			}





		    }

		//end of down searching

		for (int x = row - 1 ; x >= 0 ; x--)
		    for (int y = colume - 1 ; y >= 0 ; y--)
		    {
			if (line [x] [y] == '.' && boo [x] [y] == false && Close (x, y, row, colume, boo))
			{


			    boo [x] [y] = true;
			    valid = true;
			    counter++;

			}

		    } //end of upsearching

		if (valid == false && boo4 == false)
		{
		    for (char ch = 'a' ; ch <= 'j' ; ch++)
		    {
			for (int x2 = 0 ; x2 < row ; x2++)
			    for (int y2 = 0 ; y2 < colume ; y2++)
			    {
				if (line [x2] [y2] == ch)
				{
				    if (Close (x2, y2, row, colume, boo))
				    {
					valid = true;
					boo [x2] [y2] = true;
					counter++;
					counter++;
					boo4 = true;
					for (int x3 = 0 ; x3 < row ; x3++)
					    for (int y3 = 0 ; y3 < colume ; y3++)
					    {
						if (line [x3] [y3] == Character.toUpperCase (ch))
						    boo [x3] [y3] = true;
					    }

				    }

				}

			    }
		    }


		}


	    }
	    while (valid == true);
	    //end of searching



	    output.println (counter);
	} //end of big for loop







	input.close ();
	output.close ();
    } //of of main method


    public static boolean Close (int x, int y, int row, int colume, boolean[] [] boo)
    {
	boolean[] boo2 = new boolean [4];
	if (x != 0)
	{
	    if (boo [x - 1] [y] == true)
		boo2 [0] = true;
	}


	if (x != row - 1)
	{
	    if (boo [x + 1] [y] == true)
		boo2 [1] = true;
	}


	if (y != 0)
	{
	    if (boo [x] [y - 1] == true)
		boo2 [2] = true;
	}


	if (y != colume - 1)
	{
	    if (boo [x] [y + 1] == true)
		boo2 [3] = true;
	}


	boolean sumboo = false;
	for (int i = 0 ; i < 4 ; i++)
	{
	    if (boo2 [i] == true)
		sumboo = true;
	}


	return sumboo;




    } //end of Close method
}



