#include <bits/stdc++.h>
#define N 52
using namespace std;
typedef vector<vector<bool> > V;
typedef pair<int,int> P;
typedef pair<P,P> PP;
string mp[N];
vector<PP> A;
int h,w;

bool compare(PP &a,PP &b){
  int w1 = a.second.first - a.first.first+1;
  int h1 = a.second.second - a.first.second+1; 
  int w2 = b.second.first - b.first.first+1;
  int h2 = b.second.second -b.first.second+1;
  return h1*w1 < h2*w2;
}

V v[50][50];
void visit(int x,int y){
  V &D = v[y][x] = V(N,vector<bool>(N,0));
  D[y][x] = 1;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) {
      if(mp[i][j] == '#')continue;
      if(i)D[i][j] = D[i][j]|D[i-1][j];
      if(j)D[i][j] = D[i][j]|D[i][j-1];
    }
}

void pushA(int x,int y){
  V &D = v[y][x];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(!D[i][j]||islower(mp[i][j])||tolower(mp[i][j])!=mp[y][x])continue;
      A.push_back(PP(P(x,y),P(j,i)));
    }
}

void mkA(){
  A.clear();
  V &D = v[0][0];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(D[i][j]&&islower(mp[i][j]))pushA(j,i);
  
  sort(A.begin(),A.end(),compare);
}

bool check(PP a,PP b){
  int x1=a.first.first,y1=a.first.second;
  int X1=a.second.first,Y1=a.second.second;
  int x2=b.first.first,y2=b.first.second;
  int X2=b.second.first,Y2=b.second.second;
  if((a.first==b.first||a.second == b.second)||
     (x1>=0&&y1>=0&&!v[y1][x1][y2][x2])||
     (!v[Y2][X2][h-1][w-1])||
     (X1<w&&X2<h&&!v[Y2][X2][Y1][X1]))return 0;
  return x1<=x2&&X2<=X1&&y1<=y2&&Y2<=Y1;
}

map<PP,int> mem[1000];
int dfs(int idx,PP sta){  
  if(idx == -1) return 0;
  if(mem[idx].count(sta))return mem[idx][sta];
  int res = dfs(idx-1,sta);
  if(check(sta,A[idx])){
    int a = dfs(idx-1,PP(sta.first,A[idx].first));
    int b = dfs(idx-1,A[idx]);
    int c = dfs(idx-1,PP(A[idx].second,sta.second));
    res = max(res,a+b+c+1);
  }
  return mem[idx][sta] = res;
}

int main(){
  while(1){
    cin>>h>>w;
    if(!h&&!w)break;
    for(int i=0;i<h;i++)cin>>mp[i];
    for(int i=0;i<1000;i++)mem[i].clear();

    visit(0,0),visit(w-1,h-1);
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)if(isalpha(mp[i][j]))visit(j,i);
    
    mkA();
    if(!v[0][0][h-1][w-1]) cout<<-1<<endl;
    else cout<<dfs(A.size()-1,PP(P(-1,-1),P(w,h)))<<endl;
  }
}