#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int dp[50][50][50][50],dx[2][4]={{1,0,1,0},{-1,0,0,-1}},dy[2][4]={{0,1,0,1},{0,-1,-1,0}},u[50][50],INF=1<<29;
string s[50];
vector<P> v[26];

int dfs(int x1,int y1,int x2,int y2) {
  if(x1==x2&&y1==y2) return 0;
  if(dp[x1][y1][x2][y2]>=0) return dp[x1][y1][x2][y2];
  dp[x1][y1][x1][y1]=0;
  for(int i=x1;i<=x2;i++) {
    for(int j=y1;j<=y2;j++) {
      if(s[i][j]=='#') continue;
      if(i!=x1&&s[i-1][j]!='#') dp[x1][y1][i][j]=max(dp[x1][y1][i][j],dp[x1][y1][i-1][j]);
      if(j!=y1&&s[i][j-1]!='#') dp[x1][y1][i][j]=max(dp[x1][y1][i][j],dp[x1][y1][i][j-1]);
      if(islower(s[i][j])) {
        int c=s[i][j]-'a';
        for(int l=0; l<v[c].size(); l++) {
          int x=v[c][l].first,y=v[c][l].second;
          if(P(i,j+1)==P(x,y)||P(i+1,j)==P(x,y)) {
            if(i!=x1) dp[x1][y1][x][y]=max(dp[x1][y1][x][y],dp[x1][y1][i-1][j]+1);
            if(j!=y1) dp[x1][y1][x][y]=max(dp[x1][y1][x][y],dp[x1][y1][i][j-1]+1);
            if(i==x1&&j==y1) dp[x1][y1][x][y]=max(dp[x1][y1][x][y],dp[x1][y1][i][j]+1);
          }
          for(int k=0; k<4; k++) {
            int xx1=i+dx[0][k],yy1=j+dy[0][k];
            int xx2=x+dx[1][k],yy2=y+dy[1][k];
            if(xx1>xx2||yy1>yy2) continue;
            if(xx1<x1||xx1>x2||xx2<x1||xx2>x2) continue;
            if(yy1<y1||yy1>y2||yy2<y1||yy2>y2) continue;
            if(s[xx1][yy1]=='#'||s[xx2][yy2]=='#') continue;
            if(i!=x1) dp[x1][y1][x][y]=max(dp[x1][y1][x][y],dp[x1][y1][i-1][j]+dfs(xx1,yy1,xx2,yy2)+1);
            if(j!=y1) dp[x1][y1][x][y]=max(dp[x1][y1][x][y],dp[x1][y1][i][j-1]+dfs(xx1,yy1,xx2,yy2)+1);
            if(i==x1&&j==y1) dp[x1][y1][x][y]=max(dp[x1][y1][x][y],dp[x1][y1][i][j]+dfs(xx1,yy1,xx2,yy2)+1);
          }
        }
      }
    }
  }
  return dp[x1][y1][x2][y2];
}
int main() {
  int n,m;
  while(cin >> n >> m && n) {
    for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<n;k++)for(int l=0;l<m;l++)dp[i][j][k][l]=-INF;
    for(int i=0;i<26;i++)v[i].clear();
    memset(u,0,sizeof(u));
    u[0][0]=1;
    for(int i=0; i<n; i++) {
      cin >> s[i];
      for(int j=0; j<m; j++) if(isupper(s[i][j])) v[s[i][j]-'A'].push_back(P(i,j));
    }
    int ans=dfs(0,0,n-1,m-1);
    if(ans<0) ans=-1;
    cout << ans << endl;
  }
  return 0;
}
