import std.stdio, std.algorithm;

int getNum(ulong state, int i){
	return (state >> i*4) & 0xf;
}
ulong setNum(ref ulong state, int i, int j){
	state &= ~(0xfuL<<i*4);
	return state |= (j&0xfuL)<<i*4;
}
ulong decNum(ref ulong state, int i){
	return state -= 1uL<<i*4;
}

int solve(ulong state, int[][] landNeighbor, int[][] numNeighbor, int dim = 0, int[ulong] memo = [0:0]){
	if(int* res = state in memo) return *res;
	
	int rec(int chestnum, ulong state, int[] neighbors){
		if(chestnum == 0) return solve(state, landNeighbor, numNeighbor, dim+1, memo);
		int result = int.max;
		foreach(i, land; neighbors[0..$-chestnum+1]){
			bool ok = true;
			ulong newState = state;
			foreach(num; landNeighbor[land]){
				int cnum;
				if((cnum = newState.getNum(num)) == 0){
					ok = false;
					break;
				}
				newState.setNum(num, cnum-1);
			}
			if(ok) result = result.min(rec(chestnum-1, newState, neighbors[i+1..$]));
		}
		return result;
	}
	
	int num = state.getNum(dim);
	int result = rec(num, state, numNeighbor[dim]);
	if(result != int.max) result += num;
	return memo[state] = result;
}

void main(){
	while(true){
		int h, w;
		readf("%d %d\n", &h, &w);
		if(h == 0 || w == 0) break;
		int[2][] land;
		int[2][] num;
		ulong numstate = 0;
		char[] buf;
		int rad = 0;
		foreach(y; 0..h){
			readln(buf);
			foreach(int x, c; buf[0..$-1]){
				switch(c){
				case '.': break;
				case '*': land ~= [y,x]; break;
				default:
					if('0' <= c && c <= '9'){
						land ~= [y,x];
						if(c != '0') {
							num ~= [y,x];
							numstate.setNum(rad++, c-'0');
						}
						break;
					}
				}
			}
		}
		int[][] numNeighbor, landNeighbor;
		numNeighbor = new int[][num.length];
		foreach(k; land){
			int landNum = -1;
			foreach(y; max(0,k[0]-1)..min(h,k[0]+1)+1)
				foreach(x; max(0,k[1]-1)..min(w,k[1]+1)+1){
					int n = num.countUntil([y, x]);
					if(n >= 0){
						if(landNum == -1) {
							landNum = landNeighbor.length;
							landNeighbor ~= [n];
						}else{
							landNeighbor[landNum] ~= n;
						}
						numNeighbor[n] ~= landNum;
					}
				}
		}
		writeln(solve(numstate, landNeighbor, numNeighbor));
	}
}