A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.

The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.

The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...

Input

The first line of input contains two integers H and W (1 ≤ H, W ≤ 5), separated by a space, — the height and the width of the cake.

The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.

Output

Output the number of berries the mouse will eat following her strategy.

Examples

Input


4 3
*..
.*.
..*
...


Output


3


Input


4 4
.*..
*...
...*
..*.


Output


2


Input


3 4
..**
*...
....


Output


1


Input


5 5
..*..
.....
**...
**...
**...


Output


1

Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Implementation

Shortest paths
Skill types: Greedy algorithms

Starter code:

Solutions:
(h, w) = map(int, input().split())
grid = []
for i in range(h):
	grid.append(input())
(r, c) = (0, 0)
ans = 0
for i in range(h + w - 2):
	if grid[r][c] == '*':
		ans += 1
	if r == h - 1:
		c += 1
		continue
	if c == w - 1:
		r += 1
		continue
	right = (111111, 111)
	for row in range(r, h):
		if '*' in grid[row][c + 1:]:
			right = min(right, (grid[row][c + 1:].index('*'), row - r))
	down = (11111, 111)
	for col in range(c, w):
		column = [grid[r][col] for r in range(r + 1, h)]
		if '*' in column:
			down = min(down, (column.index('*'), col - c))
	if down < right:
		r += 1
	else:
		c += 1
if grid[r][c] == '*':
	ans += 1
print(ans)


(H, W) = map(int, input().split())
S = [input() for i in range(H)]
(x, y) = (0, 0)
ans = 0
if S[0][0] == '*':
	ans += 1
while True:
	(nx, ny) = (None, None)
	for i in range(H):
		for j in range(W):
			if S[i][j] == '*' and i >= x and (j >= y) and ((i, j) != (x, y)):
				if nx == None:
					(nx, ny) = (i, j)
				elif abs(nx - x) + abs(ny - y) > abs(i - x) + abs(j - y):
					(nx, ny) = (i, j)
	if nx != None:
		(x, y) = (nx, ny)
		ans += 1
	else:
		break
print(ans)


(n, m) = map(int, input().split())
g = [input() for i in range(n)]

def rec(i, j, ans):
	if i == n - 1 and j == m - 1:
		print(ans + (g[i][j] == '*'))
		exit()
	add = g[i][j] == '*'
	if j == m - 1:
		return rec(i + 1, j, ans + add)
	if i == n - 1:
		return rec(i, j + 1, ans + add)
	if g[i][j + 1] == '*':
		return rec(i, j + 1, ans + add)
	if g[i + 1][j] == '*':
		return rec(i + 1, j, ans + add)
	return rec(i, j + 1, ans + add)
rec(0, 0, 0)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
l = []
for i in range(n):
	for j in range(m):
		if a[i][j] == '*':
			l += [(i, j)]
now = (0, 0)
ans = int(now in l)
while True:
	mn = 99
	mnt = now
	for i in l:
		if i != now and i[0] >= now[0] and (i[1] >= now[1]) and (mn > sum(i) - sum(now)):
			mn = sum(i) - sum(now)
			mnt = i
	if mn == 99:
		break
	now = mnt
	ans += 1
print(ans)


(h, w) = map(int, input().split())
f = []
for i in range(h):
	f.append(list(str(input())))
x = 0
y = 0
res = 0
while True:
	min_r = 10 ** 9
	xm = 0
	ym = 0
	isfound = False
	for i in range(x, h):
		for j in range(y, w):
			if f[i][j] == '*':
				isfound = True
				if i - x + j - y < min_r:
					min_r = i - x + j - y
					xm = i
					ym = j
	if isfound == False:
		break
	res += 1
	f[xm][ym] = '.'
	x = xm
	y = ym
print(res)


(n, m) = map(int, input().split())
grid = [input() for i in range(n)]
(ci, cj) = (0, 0)
ate = 0
if grid[0][0] == '*':
	ate += 1
while 1:
	berry = []
	for i in range(ci, n):
		for j in range(cj, m):
			if ci == i and cj == j:
				continue
			if grid[i][j] == '*':
				berry.append((i, j))
	berry.sort(key=lambda T: (T[0] + T[1], T[0]))
	if berry:
		ate += 1
		(ci, cj) = berry[0]
	else:
		break
print(ate)


(h, w) = map(int, input().split())
s = [list(input()) for _ in range(h)]
(x, y) = (0, 0)
ans = 0
if s[0][0] == '*':
	ans += 1
while not (x == h - 1 and y == w - 1):
	if x == h - 1:
		y += 1
	elif y == w - 1:
		x += 1
	elif s[x][y + 1] == '*':
		y += 1
	elif s[x + 1][y] == '*':
		x += 1
	else:
		y += 1
	if s[x][y] == '*':
		ans += 1
print(ans)


from collections import defaultdict as dd, deque
(n, m) = [int(x) for x in input().split()]
S = [[c == '*' for c in input()] for _ in range(n)]

def next_move(sx, sy):
	Q = deque()
	Q.append((sx, sy, 0))
	res = []
	while Q:
		(x, y, d) = Q.popleft()
		if x != -1 and S[y][x] and (d > 0):
			res.append((d, y, x))
		if x != m - 1:
			Q.append((x + 1, y, d + 1))
		if x != -1 and y != n - 1:
			Q.append((x, y + 1, d + 1))
	res.sort()
	if res:
		(d, y, x) = res[0]
		return (x, y)
	return None
(x, y) = (-1, 0)
r = 0
while True:
	nxt = next_move(x, y)
	if not nxt:
		break
	(x, y) = nxt
	r += 1
print(r)


(H, W) = map(int, input().split())
cake = [input() for i in range(H)]

def dist(i, j):
	if cake[i][j] == '*':
		return 0
	if i == H - 1 and j == W - 1:
		return 1000
	if i == H - 1:
		return 1 + dist(i, j + 1)
	if j == W - 1:
		return 1 + dist(i + 1, j)
	return 1 + min(dist(i, j + 1), dist(i + 1, j))
x = 0
y = 0
result = 0
while True:
	if cake[x][y] == '*':
		result += 1
	if x == H - 1 and y == W - 1:
		break
	if x == H - 1:
		y += 1
	elif y == W - 1:
		x += 1
	elif dist(x + 1, y) < dist(x, y + 1):
		x += 1
	else:
		y += 1
print(result)


(m, n) = map(int, input().split())
A = [input() for _ in range(m)]
S = int(A[0][0] == '*')
(i, j) = (0, 0)
while i < m - 1 or j < n - 1:
	if j == n - 1 or (i < m - 1 and A[i + 1][j] == '*'):
		i += 1
	else:
		j += 1
	S += int(A[i][j] == '*')
print(S)


def canReach(x1, y1, x2, y2):
	return x1 <= x2 and y1 <= y2

def nearest(x, y):
	global cake, H, W
	for i in range(H * W):
		(x2, y2) = repere[i]
		if canReach(x, y, x2, y2) and cake[y2][x2] == '*':
			return (x2, y2)
	return (None, None)
(H, W) = map(int, input().split())
cake = []
repere = {}
(x, y) = (0, 0)
i = 0
while i < H * W:
	repere[i] = (x, y)
	x -= 1
	y += 1
	if x < 0 or y >= H:
		x += y + 1
		y = max(0, x - W + 1)
		x = min(x, W - 1)
	i += 1
for _ in range(H):
	cake += (list(input()),)
ans = 0
(x, y) = (0, 0)
while 1:
	try:
		(x, y) = nearest(x, y)
		cake[y][x] = '.'
		ans += 1
	except TypeError:
		break
print(ans)


def getDist(i, j, ii, jj):
	return abs(ii - i) + abs(jj - j)

def main():
	(n, m) = readIntArr()
	grid = []
	for _ in range(n):
		grid.append(input())
	berries = []
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '*':
				berries.append((i, j))
	ans = 0
	i = 0
	j = 0
	if grid[i][j] == '*':
		ans += 1
	while True:
		potential = []
		for (ii, jj) in berries:
			if ii > i and jj >= j or (ii >= i and jj > j):
				potential.append((ii, jj))
		if len(potential) == 0:
			break
		minDist = inf
		for (ii, jj) in potential:
			minDist = min(minDist, getDist(i, j, ii, jj))
		potential2 = []
		for (ii, jj) in potential:
			if getDist(i, j, ii, jj) == minDist:
				potential2.append((ii, jj))
		minI = inf
		for (ii, jj) in potential2:
			minI = min(minI, ii)
		for (ii, jj) in potential2:
			if ii == minI:
				i = ii
				j = jj
				break
		ans += 1
	print(ans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _aa in range(1):
	main()


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
ans = 0

def solve():
	(n, m) = aj()
	S = []
	for i in range(n):
		s = input()
		S.append([*s])

	def findclosest(x, y):
		l = []
		for i in range(y + 1, m):
			if S[x][i] == '*':
				l.append((i - y, x, i))
				break
		for i in range(x + 1, n):
			if S[i][y] == '*':
				l.append((i - x, i, y))
				break
		for i in range(x + 1, n):
			for j in range(y + 1, m):
				if S[i][j] == '*':
					l.append((i - x + (j - y), i, j))
		l.sort()
		return l

	def fun(i, j, count):
		global ans
		ans = max(ans, count)
		if i >= n or j >= m:
			return
		l = findclosest(i, j)
		if not l:
			return
		fun(l[0][1], l[0][2], count + 1)
	if S[0][0] == '*':
		fun(0, 0, 1)
	else:
		fun(0, 0, 0)
	print(ans)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


(n, m) = map(int, input().split())
cake = []
for i in range(n):
	line = input()
	cake.append(line)
berries = 0
(i, j) = (0, 0)
if cake[0][0] == '*':
	berries += 1
while j < m and i < n:
	if j + 1 < m and cake[i][j + 1] == '*':
		berries += 1
		j += 1
	elif i + 1 < n and cake[i + 1][j] == '*':
		berries += 1
		i += 1
	elif j + 1 < m:
		j += 1
	else:
		i += 1
print(berries)


import sys
input = sys.stdin.readline
(m, n) = map(int, input().split())
A = [input()[:-1] for _ in range(m)]
S = int(A[0][0] == '*')
(i, j) = (0, 0)
while i < m - 1 or j < n - 1:
	if j == n - 1 or (i < m - 1 and A[i + 1][j] == '*'):
		i += 1
	else:
		j += 1
	S += int(A[i][j] == '*')
print(S)


(n, m) = map(int, input().split(' '))
grid = []
for i in range(n):
	grid.append(input())
frontier = [(0, 0)]
total = 0
while len(frontier) > 0:
	cur = frontier.pop(0)
	if cur[0] < n and cur[1] < m:
		if grid[cur[0]][cur[1]] == '*':
			total += 1
			frontier = []
		frontier.append((cur[0], cur[1] + 1))
		frontier.append((cur[0] + 1, cur[1]))
print(total)


import os
from io import BytesIO, IOBase
import sys

def main():
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(input())
	x = y = ans = 0
	if a[0][0] == '*':
		ans += 1
	while x < n and y < m:
		(xx, yy) = (n - 1, m - 1)
		dis = 10 ** 18
		for i in range(x, n):
			for j in range(y, m):
				if i == x and j == y:
					continue
				if a[i][j] == '*':
					if i - x + j - y < dis:
						dis = i - x + j - y
						xx = i
						yy = j
					elif i - x + j - y == dis and j > yy:
						xx = i
						yy = j
		if xx == n - 1 and yy == m - 1:
			ans += a[n - 1][m - 1] == '*'
			break
		(x, y) = (xx, yy)
		ans += 1
	print(ans)
	return
BUFSIZE = 1048576

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math

def solve(cake, H, W):
	ans = 0
	cur = [0, 0]
	while cur != [H - 1, W - 1]:
		hc = cur[0]
		wc = cur[1]
		if cake[hc][wc] == '*':
			ans = ans + 1
		if wc < W - 1 and cake[hc][wc + 1] == '*':
			wc = wc + 1
		elif hc < H - 1 and cake[hc + 1][wc] == '*':
			hc = hc + 1
		elif wc < W - 1:
			wc = wc + 1
		else:
			hc = hc + 1
		cur = [hc, wc]
	if cake[H - 1][W - 1] == '*':
		ans = ans + 1
	return ans
st = input()
[H, W] = [int(x) for x in st.split()]
cake = []
for i in range(H):
	cake.append(input())
print(solve(cake, H, W))


(n, m) = input().split(' ')
n = int(n)
m = int(m)
tort = []
cherry = []
INF = 100
for line in range(n):
	temp = []
	string = input()
	for j in range(m):
		temp.append(string[j])
	tort.append(temp)
count = 0
for i in range(n):
	for j in range(m):
		if tort[i][j] == '*':
			temp = [i, j]
			cherry.append(temp)
mish = [0, 0]
while True:
	dlina = INF
	ans = [-1, -1]
	for i in cherry:
		if i[0] - mish[0] >= 0 and i[1] - mish[1] >= 0:
			if mish == i:
				count += 1
			elif i[0] - mish[0] + i[1] - mish[1] < dlina:
				dlina = i[0] - mish[0] + i[1] - mish[1]
				ans = i
	if ans[0] == -1:
		print(count)
		exit()
	mish = ans
print(count)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
i = 0
j = 0
ans = 0
while True:
	if a[i][j] == '*':
		ans += 1
	nearest_i = -1
	nearest_j = -1
	for i1 in range(i, n):
		for j1 in range(j, m):
			if i1 == i and j1 == j:
				continue
			if a[i1][j1] == '*':
				if nearest_i == -1 or i1 + j1 < nearest_i + nearest_j:
					nearest_i = i1
					nearest_j = j1
	if nearest_i == -1:
		break
	i = nearest_i
	j = nearest_j
print(ans)


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	(h, w) = map(int, input().split())
	cake = [input() for _ in range(h)]
	mx = 0
	my = 0
	res = 0
	if cake[0][0] == '*':
		res += 1
	while mx < w:
		for i in range(1, w - mx + h - my):
			for j in range(0, i + 1):
				x = mx + i - j
				y = my + j
				if x < w and y < h and (cake[y][x] == '*'):
					res += 1
					mx = x
					my = y
					break
			else:
				continue
			break
		else:
			mx = w
	print(res)
main()


def clouded_strategy(H, W, cake):
	ans = int(cake[0][0] == '*')
	(i, j) = (0, 0)
	prev = 'S'
	while (i, j) != (H - 1, W - 1):
		if i == H - 1 or j == W - 1:
			if i == H - 1 and j != W - 1:
				j += 1
			if j == W - 1 and i != H - 1:
				i += 1
			ans += int(cake[i][j] == '*')
		elif cake[i][j + 1] != '*' and cake[i + 1][j] != '*':
			if prev == 'E':
				(i, j) = (i + 1, j)
				prev == 'S'
			if prev == 'S':
				(i, j) = (i, j + 1)
				prev == 'E'
		elif cake[i][j + 1] == '*':
			(i, j) = (i, j + 1)
			prev == 'E'
			ans += 1
		else:
			(i, j) = (i + 1, j)
			prev == 'S'
			ans += 1
	print(ans)
(H, W) = map(int, input().split(' '))
cake = [[] for i in range(H)]
for i in range(H):
	cake[i] = list(input())
clouded_strategy(H, W, cake)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().strip()

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	while True:
		try:
			x = input().strip()
			if x == 'Is it rated?':
				print('NO')
				sys.stdout.flush()
		except EOFError:
			break

def solve_b():
	n = get_int()
	while len(str(n)) > 1:
		n = sum([int(char) for char in str(n)])
	return n

def solve_c():
	alpha = {char: i for (i, char) in enumerate(string.ascii_lowercase)}
	s = get_str().lower()
	n = len(s)
	for i in range(2, n):
		if (alpha[s[i - 1]] + alpha[s[i - 2]] - alpha[s[i]]) % 26 != 0:
			return 'NO'
	return 'YES'

def solve_d():
	(n, m) = get_ints()
	S = set()
	while n:
		if n % m in S:
			return 'NO'
		else:
			S.add(n % m)
		n //= m
	return 'YES'

def solve_e():
	(H, W) = get_ints()
	grid = [get_str() for _ in range(H)]
	pos = [0, 0]
	ans = 0
	while pos != [6, 6]:
		if grid[pos[0]][pos[1]] == '*':
			ans += 1
		nearest = [7, 7]
		nearest_pos = [6, 6]
		for h in range(pos[0], H):
			for w in range(pos[1], W):
				if h + w == pos[0] + pos[1]:
					continue
				if grid[h][w] == '.':
					continue
				dist = h + w - pos[0] - pos[1]
				if [dist, h] < nearest:
					nearest = [dist, h]
					nearest_pos = [h, w]
		pos = nearest_pos[:]
	return ans
print(solve_e())


import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
mo = int(1000000000.0 + 7)

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return -1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0

def orafli(upp):
	primes = []
	marked = [False for i in range(upp + 3)]
	prvs = [i for i in range(upp + 3)]
	for i in range(2, upp):
		if not marked[i]:
			primes.append(i)
		for j in primes:
			if i * j >= upp:
				break
			marked[i * j] = True
			prvs[i * j] = j
			if i % j == 0:
				break
	return (primes, prvs)

def lower_ord(c: str) -> int:
	return ord(c) - 97

def upper_ord(c: str) -> int:
	return ord(c) - 65

def read_list():
	return [int(i) for i in input().split()]

def read_int():
	s = input().split()
	if len(s) == 1:
		return int(s[0])
	else:
		return map(int, s)

def ask(s):
	print(f'? {s}', flush=True)

def answer(s):
	print(f'{s}', flush=True)
mo = int(1000000000.0 + 7)
d = {(1, 0, 0, 1, 0): 'a', (2, 0, 0, 1, 1): 'c', (2, 1, 0, 1, 2): 'd', (1, 1, 0, 1, 1): 'e', (2, 1, 0, 2, 1): 'f', (1, 1, 1, 2, 1): 'o', (1, 2, 1, 3, 1): 'r', (1, 1, 2, 2, 2): 'z'}
pss = []

def solve():
	(n, m) = read_int()
	a = []
	for i in range(n):
		a.append(input())
	x = 0
	y = 0
	ans = 0
	d = 0
	if a[0][0] == '*':
		ans += 1
	while True:
		(xx, yy) = (n - 1, m - 1)
		ds = int(114514191981093111)
		for i in range(x, n):
			for j in range(y, m):
				if i == x and y == j:
					continue
				if a[i][j] == '*':
					if i - x + j - y < ds:
						ds = i - x + j - y
						xx = i
						yy = j
					elif i - x + j - y == ds and j > yy:
						ds = i - x + j - y
						xx = i
						yy = j
		if xx == n - 1 and yy == m - 1:
			ans += a[n - 1][m - 1] == '*'
			break
		(x, y) = (xx, yy)
		ans += 1
	print(ans)
solve()


(n, m) = map(int, input().split())
a = [[x for x in input()] for _ in range(n)]
i = 0
j = 0
ans = 0
while True:
	found = False
	for x in range(100):
		for t in range(0, x + 1):
			ni = i + t
			nj = j + x - t
			if ni < n and nj < m and (a[ni][nj] == '*'):
				ans += 1
				found = True
				i = ni
				j = nj
				a[ni][nj] = '.'
				break
		if found:
			break
	if not found:
		break
print(ans)


(r, c) = map(int, input().split())
cake = []
for i in range(r):
	cake.append(list(input()))
i = 0
j = 0
berries = 0
if cake[0][0] == '*':
	berries += 1
while i < r and j < c:
	if j + 1 < c and i < r:
		if cake[i][j + 1] == '*':
			berries += 1
			j += 1
		elif i + 1 < r and j < c:
			if cake[i + 1][j] == '*':
				berries += 1
				i += 1
			else:
				j += 1
		else:
			j += 1
	elif i + 1 < r and j < c:
		if cake[i + 1][j] == '*':
			berries += 1
			i += 1
		else:
			j += 1
	else:
		i += 1
if j < c - 1:
	for k in range(j + 1, c):
		if cake[i - 1][k] == '*':
			berries += 1
if i < r - 1:
	for k in range(i + 1, r):
		if cake[k][j - 1] == '*':
			berries += 1
print(berries)


(h, w) = [int(i) for i in input().strip().split()]
l = [[i for i in input()] for i in range(h)]
count = 0
(i, j) = (0, 0)
if l[0][0] == '*':
	count += 1
while True:
	if i == h - 1 and j == w - 1:
		break
	down = -1
	right = -1
	if i + 1 < h:
		if l[i + 1][j] == '*':
			down = 1
		else:
			down = 0
	if j + 1 < w:
		if l[i][j + 1] == '*':
			right = 1
		else:
			right = 0
	if down == 1:
		i += 1
		count += 1
		continue
	if right == 1:
		j += 1
		count += 1
		continue
	if right == 0 and down == 0:
		j += 1
		continue
	if right == -1:
		i += 1
		continue
	if down == -1:
		j += 1
		continue
print(count)


(h, w) = map(int, input().split(' '))
s = []
for i in range(h):
	s.append(input())
i = 0
j = 0
c = 0
while i < h or j < w:
	if s[i][j] == '*':
		c = c + 1
	if j < w - 1 and s[i][j + 1] == '*':
		j = j + 1
	elif i < h - 1 and s[i + 1][j] == '*':
		i = i + 1
	elif i == h - 1 and j < w - 1:
		j = j + 1
	elif j == w - 1 and i < h - 1:
		i = i + 1
	elif j < w - 1:
		j = j + 1
	elif i < h - 1:
		i = i + 1
	else:
		break
print(c)


(n, m) = map(int, input().split())
ar = [input() for i in range(n)]
x = 0
y = 0
res = 0
while True:
	res += 1 if ar[x][y] == '*' else 0
	if x == n - 1 and y == m - 1:
		break
	elif x == n - 1:
		y += 1
	elif y == m - 1:
		x += 1
	elif ar[x][y + 1] == '*':
		y += 1
	elif ar[x + 1][y] == '*':
		x += 1
	else:
		y += 1
print(res)


(h, w) = list(map(int, input().split()))
arr = []
points = []
for i in range(h):
	arr.append(input())
	for j in range(len(arr[i])):
		if arr[i][j] == '*':
			points.append([i, j])
start = [0, 0]
end = [h - 1, w - 1]
cur = [0, 0]
count = 0
while cur != end:
	min_dist = 100
	next = []
	for point in points:
		if point[0] >= cur[0] and point[1] >= cur[1]:
			dist = point[0] - cur[0] + (point[1] - cur[1])
			if dist < min_dist:
				min_dist = dist
				next = point
	if min_dist == 100:
		cur = end
		break
	else:
		cur = next
		del points[points.index(next)]
		count += 1
print(count)


def calc_dist(t1, t2):
	(x1, y1) = t1
	(x2, y2) = t2
	return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
(h, w) = [int(x) for x in input().split()]
arr = [['0'] * w] * h
locations = []
for i in range(h):
	line = [x for x in input()]
	for j in range(w):
		if line[j] == '*':
			locations.append([i, j])
		arr[i][j] = line[j]
locations.append([h, w])
count = 0
curr = [0, 0]
closest = [h, w]
dist = 99999999999999999999999999999999999999999999
if curr in locations:
	count += 1
while curr != [h, w]:
	dist = 99999999999999999999999999999999999999999999
	for location in locations:
		if location[0] < curr[0] or location[1] < curr[1] or location == curr:
			continue
		if calc_dist(curr, location) < dist:
			dist = calc_dist(curr, location)
			closest = location
	curr = closest
	if curr != [h, w]:
		count += 1
print(count)


(h, w) = map(int, input().split())
a = []
for _ in range(h):
	a.append(input())
(i, j, k) = (0, 0, 0)
while i < h:
	if a[i][j] == '*':
		k += 1
	if i != h - 1 and a[i + 1][j] == '*' or j == w - 1:
		i += 1
	else:
		j += 1
print(k)


from math import inf

def ke(q):
	d1 = q[0] - hc
	d2 = q[1] - wc
	if d1 < 0 or d2 < 0 or d1 == d2 == 0:
		return (inf, inf)
	return (d1 + d2, d1)
(h, w) = map(int, input().split())
a = [list(map(lambda x: x == '*', input())) for i in range(h)]
(hc, wc) = (0, 0)
cnt = 0
while hc != h - 1 or wc != w - 1:
	nxtc = min([(i, j) for i in range(h) for j in range(w) if a[i][j]] + [(h - 1, w - 1)], key=ke)
	(hc, wc) = nxtc
	if a[hc][wc]:
		cnt += 1
print(cnt + a[0][0])


(y, x) = list(map(int, input().split()))
board = []
for i in range(y):
	board.append(input())
posX = 0
posY = 0
score = 0
turn = 0
last = 'y'
while True:
	if posY >= y or posX >= x:
		break
	if board[posY][posX] == '*':
		score += 1
	if posX + 1 < x and board[posY][posX + 1] == '*':
		posX += 1
		last = 'x'
	elif posY + 1 < y and board[posY + 1][posX] == '*':
		posY += 1
		last = 'y'
	elif last == 'x':
		if posY + 1 < y:
			posY += 1
			last = 'y'
		else:
			posX += 1
			last = 'x'
	elif posX + 1 < x:
		posX += 1
		last = 'x'
	else:
		posY += 1
		last = 'y'
print(score)


import itertools
import sys
from typing import List

def solve_E(board: List[List[str]]) -> int:
	(n, m) = (len(board), len(board[0]))
	(x, y) = (0, 0)
	goal = (n - 1, m - 1)
	ans = int(board[0][0] == '*')
	while (x, y) != goal:
		(tx, ty) = min(((i, j) for (i, j) in itertools.product(range(x, n), range(y, m)) if (i, j) != (x, y) and board[i][j] == '*'), key=lambda ij: (ij[0] - x + (ij[1] - y), ij), default=goal)
		if board[tx][ty] == '*':
			ans += 1
		(x, y) = (tx, ty)
	return ans
input_str = sys.stdin.read()
print(solve_E(input_str.splitlines()[1:]))


class Test:

	def __init__(self):
		self.a = 1

	def input(self):
		line = input()
		line = [int(i) for i in line.split(' ')]
		(M, N) = (line[0], line[1])
		map = []
		for i in range(M):
			line = input().strip()
			line = [i for i in line]
			map.append(line)
		x = 0
		y = 0
		ans = 0
		if map[0][0] == '*':
			ans = 1
		while True:
			flag = False
			for i in range(1, M * N):
				for j in range(i + 1):
					posx = min(M - 1, x + j)
					posy = min(N - 1, y + i - j)
					if map[posx][posy] == '*':
						flag = True
						ans += 1
						x = posx
						y = posy
						map[posx][posy] = '.'
						break
				if flag:
					break
			if flag != True:
				print(ans)
				break
a = Test()
a.input()


def try1(n, m):
	down = n
	right = m
	i = 0
	j = 0
	ans = 0
	iter = 0
	while i < n and j < m:
		if matrix[i][j] == '*':
			ans += 1
		if i == n - 1:
			if j == m - 1:
				break
			else:
				j += 1
		elif iter % 2 == 0 or j == m - 1:
			i += 1
		else:
			j += 1
		iter += 1
	return ans

def try2(n, m):
	down = n
	right = m
	i = 0
	j = 0
	ans = 0
	iter = 0
	while i < n and j < m:
		if matrix[i][j] == '*':
			ans += 1
		if i == n - 1:
			if j == m - 1:
				break
			else:
				j += 1
		elif iter % 2 == 1 or j == m - 1:
			i += 1
		else:
			j += 1
		iter += 1
	return ans

def try3(n, m):
	down = n
	right = m
	i = 0
	j = 0
	ans = 0
	iter = 0
	while i < n and j < m:
		if matrix[i][j] == '*':
			ans += 1
		if i == n - 1 and j == m - 1:
			break
		r = i + 1
		sr = 0
		fr = False
		while r < n:
			sr += 1
			if matrix[r][j] == '*':
				fr = True
				break
			r += 1
		c = j + 1
		sc = 0
		fc = False
		while c < m:
			sc += 1
			if matrix[i][c] == '*':
				fc = True
				break
			c += 1
		if fc and fr:
			if sc <= sr:
				j = c
			else:
				i = r
		elif fc:
			j = c
		elif fr:
			i = r
		elif j < m - 1:
			j += 1
		else:
			i += 1
	return ans

def try4(n, m):
	li = []
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == '*':
				li.append((i, j))
	nearest_best = -1
	r = 0
	c = 0
	ans = 0
	while True:
		nearest_best = -1
		dist_best = 100
		for i in range(len(li)):
			(x, y) = li[i]
			if x >= r and y >= c:
				curr_dist = x - r + (y - c)
				if curr_dist < dist_best:
					dist_best = curr_dist
					nearest_best = i
				elif curr_dist == dist_best:
					if x < li[nearest_best][0]:
						nearest_best = i
		if nearest_best == -1:
			break
		ans += 1
		r = li[nearest_best][0]
		c = li[nearest_best][1]
		li.pop(nearest_best)
	return ans
(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	row = input()
	matrix.append(row)
ans = try4(n, m)
print(ans)


import sys
import math
from bisect import bisect_left
import heapq

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()

def FACT(n, mod):
	s = 1
	facts = [1]
	for i in range(1, n + 1):
		s *= i
		s %= mod
		facts.append(s)
	return facts[n]

def C(n, k, mod):
	return FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
(h, w) = MI()
l = []
for i in range(h):
	l.append(list(SI()))
x = 0
y = 0
count = 0
while x != h - 1 or y != w - 1:
	if l[x][y] == '*':
		count += 1
	if x == h - 1:
		y += 1
	elif y == w - 1:
		x += 1
	elif l[x][y + 1] == '*':
		y += 1
	elif l[x + 1][y] == '*':
		x += 1
	else:
		y += 1
if l[h - 1][w - 1] == '*':
	count += 1
print(count)


(h, w) = map(int, input().split())
arr = [input() for i in range(h)]
a = 0
b = 0
cnt = int(arr[a][b] == '*')
while True:
	x = 10 ** 9
	y = 10 ** 9
	for i in range(a, h):
		for j in range(b, w):
			if i == a and j == b:
				continue
			if arr[i][j] == '.':
				continue
			if i - a + j - b < x - a + y - b:
				x = i
				y = j
	if x == 10 ** 9:
		break
	a = x
	b = y
	cnt += 1
print(cnt)


(n, m) = map(int, input().split())
field = []
for line in range(n):
	field.append(list(input()))
x = 0
y = 0
berries = 0
while x != m - 1 or y != n - 1:
	if field[y][x] == '*':
		berries += 1
	if x == m - 1:
		y += 1
	elif y == n - 1:
		x += 1
	elif field[y][x + 1] == '*':
		x += 1
	elif field[y + 1][x] == '*':
		y += 1
	else:
		x += 1
if field[y][x] == '*':
	berries += 1
print(berries)


(row, col) = map(int, input().split())
matrix = []
for i in range(row):
	matrix.append(list(input()))
i = 0
j = 0
r = 0
while not (i == row - 1 and j == col - 1):
	if matrix[i][j] == '*':
		r += 1
	if i == row - 1:
		j += 1
	elif j == col - 1:
		i += 1
	elif matrix[i][j + 1] == '*':
		j += 1
	elif matrix[i + 1][j] == '*':
		i += 1
	else:
		j += 1
if matrix[i][j] == '*':
	r += 1
print(r)


import sys
(h, w) = map(int, input().split())
lines = []
for i in range(h):
	lines.append(input())
(ci, cj) = (0, 0)
ans = 1 if lines[0][0] == '*' else 0
while True:
	(ni, nj) = (1000, 1000)
	for i in range(ci, h):
		for j in range(cj, w):
			if i + j > ci + cj and lines[i][j] == '*' and (i - ci + (j - cj) < ni - ci + (nj - cj)):
				(ni, nj) = (i, j)
	if ni == 1000:
		break
	(ci, cj) = (ni, nj)
	ans += 1
print(ans)


(h, w) = [int(i) for i in input().split()]
(a, b) = (1, 1)
cherry = []
r = 0
for i in range(h):
	line = input()
	for j in range(w):
		if line[j] == '*':
			cherry.append((i + 1, j + 1))

def remov(point):
	global a, b
	(_p1, _p2) = point
	if _p1 < a or _p2 < b:
		return False
	else:
		return True

def distance(point):
	global a, b
	(_p1, _p2) = point
	return abs(a - _p1) + abs(b - _p2)

def srt(point):
	(_p1, _p2) = point
	return (distance(point), _p1, _p2)
while True:
	if a == h and b == w:
		break
	cherry = list(filter(remov, cherry))
	cherry.sort(key=srt)
	if not cherry:
		break
	(a, b) = cherry.pop(0)
	r += 1
print(r)


(a, b) = map(int, input().split())
matrix = []
for _ in range(a):
	l = input()
	matrix.append(l)
x = 0
y = 0
c = 0
while x < a - 1 or y < b - 1:
	if matrix[x][y] == '*':
		c += 1
	if x == a - 1:
		y += 1
		continue
	elif y == b - 1:
		x += 1
		continue
	xB = False
	yB = False
	if x < a - 1 and matrix[x + 1][y] == '*':
		xB = True
	if y < b - 1 and matrix[x][y + 1] == '*':
		yB = True
	if xB == yB:
		y += 1
	elif xB:
		x += 1
	else:
		y += 1
if matrix[x][y] == '*':
	c += 1
print(c)


(n, m) = [int(i) for i in input().split()]
a = [None] * n
for i in range(n):
	a[i] = [1 if i == '*' else 0 for i in input()]
cc = (0, 0)
res = 0
curdir = 1
while True:
	if a[cc[0]][cc[1]]:
		res += 1
	if cc == (n - 1, m - 1):
		break
	distright = 1000
	if cc[0] == n - 1:
		distright = 10000
	for j in range(cc[0] + 1, n):
		if a[j][cc[1]]:
			distright = j - cc[0]
			break
	distdown = 1000
	if cc[1] == m - 1:
		distdown = 10000
	for j in range(cc[1] + 1, m):
		if a[cc[0]][j]:
			distdown = j - cc[1]
			break
	if distright < distdown:
		nxt = (cc[0] + 1, cc[1])
	else:
		nxt = (cc[0], cc[1] + 1)
	cc = nxt
print(res)


def main():
	(n, m) = map(int, input().split())
	s = [input() for _ in range(n)]
	a = [(i, j) for (i, row) in enumerate(s) for (j, x) in enumerate(row) if x == '*']
	(curx, cury) = (0, 0)
	cnt = 0
	while len(a) > 0:
		cnt += 1
		(curx, cury) = min(a, key=lambda x: (x[0] - curx + (x[1] - cury), x[0], x[1]))
		a.remove((curx, cury))
		a = [x for x in a if curx <= x[0] and cury <= x[1]]
	print(cnt)
main()


from itertools import dropwhile, takewhile, filterfalse, islice

def valida(coord):
	(x, y) = coord
	return not (x < cols and y < rens and matriz[y][x])
(rens, cols) = map(int, input().split())
matriz = [list(map(lambda x: x == '*', input())) for i in range(rens)]
bayas = dist = x = y = 0
while x + y + dist < cols + rens:
	listdist = zip(range(x + dist, x - 1, -1), range(y, y + 1 + dist))
	listdist = filterfalse(valida, listdist)
	listdist = list(islice(listdist, 1))
	if listdist != []:
		bayas += 1
		coord = listdist[0]
		(x, y) = coord
		dist = 1
	else:
		dist += 1
print(bayas)


import copy
import math
fin = None
fout = None
uabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
abet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def start(filename):
	filename = filename.replace('.py', '')
	global fin
	global fout
	infile = filename + '.in'
	outfile = filename + '.out'
	fin = open(infile)
	fout = open(outfile, 'w')

def permutation(lst):
	if len(lst) == 0:
		return []
	if len(lst) == 1:
		return [lst]
	l = []
	for i in range(len(lst)):
		m = lst[i]
		remLst = lst[:i] + lst[i + 1:]
		for p in permutation(remLst):
			l.append([m] + p)
	return l

def subsets(x):
	retset = []
	if len(x) == 0:
		retset = [[]]
	else:
		first = x[-1]
		cop = x.copy()
		cop.remove(first)
		y = subsets(cop)
		retset.extend(copy.deepcopy(y))
		m = copy.deepcopy(y)
		for i in range(len(y)):
			k = m[0]
			m.remove(k)
			k.append(first)
			m.append(k)
		retset.extend(m.copy())
	return retset

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __str__(self):
		return str(self.x) + str(self.y)

	def __hash__(self):
		return hash(str(self))

	def __eq__(self, other):
		return self.x == other.x and self.y == other.y

class frac:

	def __init__(self, n, d):
		self.n = n
		self.d = d

	def __str__(self):
		return str(self.n) + '/' + str(self.d)

	def __hash__(self):
		return hash(str(self))

	def simp(self):
		div = math.gcd(self.n, self.d)
		self.n = self.n / div
		self.d = self.d / div

	def __eq__(self, other):
		return self.n / self.d == other.n / other.d

	def __lt__(self, other):
		return self.n / self.d < other.n / other.d

class Interval:

	def __init__(self, start, end):
		self.start = start
		self.end = end

	def __str__(self):
		return str(self.start) + str(self.end)

	def __hash__(self):
		return hash(str(self))

	def __eq__(self, other):
		return self.start == other.start and self.end == other.end

	def __lt__(self, other):
		return self.start < other.start

def overlap(verl1, verl2):
	if verl1.end >= verl2.start:
		return True
	else:
		return False

def merge(verl1, verl2):
	retverl = Interval(min(verl1.start, verl2.start), max(verl1.end, verl2.end))
	return retverl

def changeBase(num, base):
	if base == 2:
		return '{0:b}'.format(num)
	power = math.floor(math.log(num, base))
	remainder = num
	end = []
	iter = list(range(power + 1))
	iter.reverse()
	for i in iter:
		if remainder >= base ** i:
			(q, r) = divmod(remainder, base ** i)
			end.append(q)
			remainder = r
		else:
			end.append(0)
	retlist = []
	for i in end:
		if i > 9:
			retlist.append(uabet[i - 10])
		else:
			retlist.append(i)
	retlist = map(str, retlist)
	return ''.join(retlist)

def prime(num):
	if num == 2:
		return True
	if num % 2 == 0:
		return False
	for i in range(2, math.ceil(num ** 0.5) + 1):
		if num % i == 0:
			return False
	return True

def fn(g, t):
	if g == [['.']]:
		print(t)
		exit()
	f = {}
	for i in range(len(g)):
		for j in range(len(g[i])):
			if g[i][j] == '*':
				if i + j in list(f.keys()):
					if j > f[i + j][1]:
						f[i + j] = [i, j]
				else:
					f[i + j] = [i, j]
	x = list(f.keys())
	if x == []:
		print(t)
		exit()
	x.sort()
	m = x[0]
	c = 0
	for i in range(len(x)):
		if x[i] == m:
			if f[x[i]][1] > f[x[c]][1]:
				c = i
	v = f[x[0]]
	t += 1
	for i in range(v[0]):
		del g[0]
	for i in g:
		for j in range(v[1]):
			del i[0]
	g[0][0] = '.'
	fn(g, t)

def main():
	(h, w) = map(int, input().split(' '))
	g = []
	for i in range(h):
		g.append(list(input()))
	fn(g, 0)
main()


(h, w) = list(map(int, input().split()))
t = [input() for _ in range(h)]
collected = 0
curr_pos = (0, 0)
if t[0][0] == '*':
	collected = 1

def collectable(i, j):
	return i >= curr_pos[0] and j >= curr_pos[1]

def dist(i, j):
	return i - curr_pos[0] + (j - curr_pos[1])
while True:
	closest = None
	for i in range(curr_pos[0], h):
		for j in range(curr_pos[1], w):
			if t[i][j] == '*' and (not (i, j) == curr_pos):
				if closest is None or dist(i, j) < dist(*closest):
					closest = (i, j)
	if closest is None:
		break
	curr_pos = closest
	collected += 1
print(collected)


import sys
import math
from collections import deque, defaultdict
from string import ascii_letters
letters = ascii_letters[:26]
ONLINE_JUDGE = 0
if any(['--local' in i for i in sys.argv]) and (not ONLINE_JUDGE):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, m) = map(int, input().split())
pos = [0, 0]
ans = 0
arr = [list(input()) for i in range(n)]
while True:
	ind = (-1, -1)
	v = 9999999
	for i in range(n):
		for g in range(m):
			if i < pos[0] or g < pos[1]:
				continue
			if arr[i][g] != '*':
				continue
			d = abs(i - pos[0]) + abs(g - pos[1])
			if d < v:
				v = d
				ind = (i, g)
	if ind[0] == -1:
		break
	arr[ind[0]][ind[1]] = '.'
	pos = (ind[0], ind[1])
	ans += 1
print(ans)


from itertools import product
import itertools
import sys
import heapq
from collections import deque
MOD = 1000000000007

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
K = sys.stdin.readline().strip().split()
H = int(K[0])
W = int(K[1])
m = []
for i in range(H):
	l = sys.stdin.readline().strip()
	m.append(l)
x = 0
y = 0
while True:
	if m[y][x] == '*':
		ans += 1
	if x == W - 1 and y == H - 1:
		break
	elif x == W - 1:
		y += 1
	elif y == H - 1:
		x += 1
	else:
		F = True
		for i in range(1, 5):
			if x + i < W and m[y][x + i] == '*':
				break
			elif y + i < H and m[y + i][x] == '*':
				F = False
				break
		if F:
			x += 1
		else:
			y += 1
print(ans)


(h, w) = map(int, input().split())
grid = [input() for i in range(h)]
x = 0
y = 0
ans = 0
while x < h - 1 or y < w - 1:
	if grid[x][y] == '*':
		ans += 1
	if x == h - 1:
		y += 1
	elif y == w - 1:
		x += 1
	else:
		d1 = 200
		d2 = 200
		for i in range(x, h):
			for j in range(y, w):
				if i == x and j == y:
					continue
				if grid[i][j] == '.':
					continue
				dd1 = abs(i - (x + 1)) + abs(j - y)
				dd2 = abs(i - x) + abs(j - (y + 1))
				d1 = min(d1, dd1)
				d2 = min(d2, dd2)
		if d1 < d2:
			x += 1
		else:
			y += 1
if grid[h - 1][w - 1] == '*':
	ans += 1
print(ans)


(n, m) = map(int, input().split())
q = [input() for i in range(n)]
i = j = c = 0
while 1:
	c += q[i][j] == '*'
	if i == n - 1 and j == m - 1:
		break
	if i == n - 1:
		j += 1
	elif j == m - 1:
		i += 1
	elif q[i + 1][j] == '*':
		i += 1
	elif q[i][j + 1] == '*':
		j += 1
	else:
		j += 1
print(c)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, m) = map(int, input().split())
l = []
ans = 0
s = []
for i in range(n):
	l.append(input())
for i in range(n):
	for j in range(m):
		if l[i][j] == '*':
			s.append((i, j))
s.sort()
pos = (0, 0)
c = 0
while True:
	mi = 100
	f = 0
	curx = pos[0]
	cury = pos[1]
	for i in range(len(s)):
		dist = 1000
		if s[i][0] >= curx and s[i][1] >= cury:
			dist = s[i][0] - curx + s[i][1] - cury
			f = 1
		if dist < mi:
			pos = s[i]
			mi = dist
	if f == 0:
		break
	s.remove(pos)
	ans += 1
print(ans)


(a, b) = map(int, input().split())
cake = []
for _ in range(a):
	cake.append([x for x in input()])
count = 0
(x, y) = (0, 0)
while x < b and y < a:
	if cake[y][x] == '*':
		count += 1
	if x < b - 1 and cake[y][x + 1] == '*':
		x += 1
	elif y < a - 1 and cake[y + 1][x] == '*':
		y += 1
	else:
		x += 1
		if x == b:
			x -= 1
			y += 1
print(count)


(H, W) = map(int, input().split())
cake = [[False] * W for i in range(H)]
for i in range(H):
	s = input()
	for j in range(W):
		if s[j] == '*':
			cake[i][j] = True
(x, y) = (0, 0)
ans = 0
while x < H and y < W:
	if cake[x][y]:
		ans += 1
	if y < W - 1 and cake[x][y + 1]:
		y += 1
		continue
	if x < H - 1 and cake[x + 1][y]:
		x += 1
		continue
	if y < W - 1:
		y += 1
		continue
	elif x < H - 1:
		x += 1
		continue
	if x == H - 1 and y == W - 1:
		break
print(ans)


(h, w) = [int(x) for x in input().split()]
maps = []
for i in range(h):
	row = input()
	rows = []
	for r in row:
		rows.append(r)
	maps.append(rows)
ans = 0 if maps[0][0] == '.' else 1
(i, j) = (0, 0)
while not (i == h - 1 and j == w - 1):
	if j + 1 < w and maps[i][j + 1] == '*':
		j += 1
		ans += 1
	elif i + 1 < h and maps[i + 1][j] == '*':
		i += 1
		ans += 1
	elif j + 1 < w:
		j += 1
	else:
		i += 1
print(ans)


(n, m) = map(int, input().split())
cake = [list(input()) for i in range(n)]
loc = (0, 0)
ans = 1 if cake[0][0] == '*' else 0
while loc != (n, m):
	best = 1000
	bestloc = (n, m)
	(x, y) = loc
	for i in range(x, n):
		for j in range(y, m):
			if cake[i][j] == '*' and (i, j) != (x, y):
				dis = i - x + j - y
				if dis < best:
					best = dis
					bestloc = (i, j)
	loc = bestloc
	if best < 1000:
		ans += 1
print(ans)


(h, w) = map(int, input().split(' '))
lis = []
for _ in range(h):
	lis.append(input())
(i, j) = (0, 0)
count = 0
if lis[h - 1][w - 1] == '*':
	count += 1
while i != h - 1 or j != w - 1:
	if lis[i][j] == '*':
		count += 1
	if j == w - 1:
		i = i + 1
	elif i == h - 1:
		j = j + 1
	try:
		if lis[i][j + 1] == '*':
			j = j + 1
		elif lis[i + 1][j] == '*':
			i = i + 1
		elif lis[i][j + 1] == '.':
			j = j + 1
		elif lis[i + 1][j] == '.':
			i = i + 1
	except:
		pass
print(count)


(h, w) = map(int, input().split())
a = [input() for i in range(h)]
berries = i = j = 0
while i < h and j < w:
	if a[i][j] == '*':
		berries += 1
	if i < h - 1 and a[i + 1][j] == '*':
		i += 1
	elif j < w - 1:
		j += 1
	else:
		i += 1
print(berries)


(h, w) = map(int, input().split())
board = [input() for _ in range(h)]
out = 0
cx = 0
cy = 0
if board[0][0] == '*':
	out += 1
while True:
	poss = []
	for i in range(h):
		for j in range(w):
			if board[i][j] == '*' and i >= cx and (j >= cy) and (i + j > cx + cy):
				poss.append((i + j, i, j))
	if poss:
		(_, cx, cy) = min(poss)
		out += 1
	else:
		break
print(out)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
x = y = 0
ans = 0
dir = 0
if a[0][0] == '*':
	ans += 1
while x < n and y < m:
	(xx, yy) = (n - 1, m - 1)
	dis = int(1e+18)
	for i in range(x, n):
		for j in range(y, m):
			if i == x and y == j:
				continue
			if a[i][j] == '*':
				if i - x + (j - y) < dis:
					dis = i - x + (j - y)
					xx = i
					yy = j
				elif i - x + (j - y) == dis and j > yy:
					dis = i - x + (j - y)
					xx = i
					yy = j
	if xx == n - 1 and yy == m - 1:
		ans += a[n - 1][m - 1] == '*'
		break
	(x, y) = (xx, yy)
	ans += 1
print(ans)


def findnext():
	bestdist = W - w + H - h
	bestw = W
	besth = H
	for hs in range(h, H):
		for ws in range(w, W):
			if hs != h or ws != w:
				if c[hs][ws] == '*':
					dist = ws - w + hs - h
					if dist < bestdist:
						bestdist = dist
						besth = hs
						bestw = ws
	return (besth, bestw)
(H, W) = list(map(int, input().split()))
c = []
for i in range(H):
	c.append(input())
h = 0
w = 0
count = 0
while h != H and w != W:
	if c[h][w] == '*':
		count += 1
	(h, w) = findnext()
print(count)


from sys import stdin, stderr
input = stdin.readline

def dbp(*args, **kwargs):
	pass

def get_int_list():
	return [int(x) for x in input().strip().split()]
(h, w) = get_int_list()
rows = [input().strip() for _ in range(h)]
r = c = t = eaten = 0
while r < h and c < w:
	dbp(r, c, h, w, eaten)
	if rows[r][c] == '*':
		eaten += 1
	std = rows[r].find('*', c + 1)
	dbp(rows[r], std)
	mvdown = False
	if std == -1:
		mvdown = True
	else:
		std -= c
		i = 1
		while r + i < h:
			rstd = rows[r + i].find('*', c)
			if rstd == -1:
				i += 1
				continue
			else:
				if i + rstd < std:
					mvdown = True
					break
				i += 1
	if mvdown == True:
		dbp('trying to move down')
		if r < h - 1:
			r += 1
		else:
			c += 1
		dbp('result:', r, c)
	else:
		dbp('trying to move across')
		if c < w - 1:
			c += 1
		else:
			r += 1
		dbp('result:', r, c)
print(eaten)


import sys
import copy

def find_closest_berries(matrix, x, y):
	max_depth = 100
	Q = []
	Q.append((x, y, 0))
	ans = []
	while Q:
		(x, y, d) = Q.pop(0)
		if d > max_depth:
			break
		if matrix[y][x] == '*':
			max_depth = d
			ans.append((x, y))
			break
		if x + 1 < len(matrix[0]):
			Q.append((x + 1, y, d + 1))
		if y + 1 < len(matrix):
			Q.append((x, y + 1, d + 1))
	return ans

def find_solution(matrix, x, y):
	B = find_closest_berries(matrix, x, y)
	if not B:
		return 0
	best = 0
	while B:
		(tx, ty) = B.pop()
		tm = copy.deepcopy(matrix)
		tm[ty][tx] = 'X'
		path_val = find_solution(tm, tx, ty) + 1
		best = max(best, path_val)
	return best
while True:
	try:
		(H, W) = map(int, input().split())
		matrix = []
		for i in range(H):
			line = input()
			line_list = []
			for j in range(W):
				line_list.append(line[j])
			matrix.append(line_list)
		ans = find_solution(matrix, 0, 0)
		print(ans)
	except EOFError:
		break


import time
import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

def getInts():
	return list(map(int, input().split()))

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return a // b + (a % b > 0)
MOD = 10 ** 9 + 7

def solve():
	(H, W) = getInts()
	grid = [listStr() for _ in range(H)]
	pos = [0, 0]
	ans = 0
	while pos != [6, 6]:
		if grid[pos[0]][pos[1]] == '*':
			ans += 1
		nearest = [7, 7]
		nearest_pos = [6, 6]
		for h in range(pos[0], H):
			for w in range(pos[1], W):
				if h + w == pos[0] + pos[1]:
					continue
				if grid[h][w] == '.':
					continue
				dist = h + w - pos[0] - pos[1]
				if [dist, h] < nearest:
					nearest = [dist, h]
					nearest_pos = [h, w]
		pos = nearest_pos[:]
	return ans
print(solve())


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	a = [input().strip() for i in range(n)]
	dp = [[0] * m for i in range(n)]
	if a[n - 1][m - 1] == '*':
		dp[n - 1][m - 1] = 1
	dd = int(1000000000.0)
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if a[i][j] == '*':
				dd = min(dd, i + j)
			if i == n - 1 and m - 1 == 0:
				continue
			if a[i][j] == '*':
				d = int(1000000000.0)
				z = int(1000000000.0)
				for ii in range(i, n):
					for jj in range(j, m):
						if ii == i and jj == j:
							continue
						if a[ii][jj] == '*':
							z = min(z, ii + jj)
				if z == int(1000000000.0):
					dp[i][j] = 1
				else:
					for ii in range(i, n):
						for jj in range(j, m):
							if a[ii][jj] == '*' and ii + jj == z:
								d = min(d, dp[ii][jj])
					dp[i][j] = d + 1
	if dd == int(1000000000.0):
		print(0)
		return
	ans = int(1000000000.0)
	for i in range(n):
		for j in range(m):
			if a[i][j] == '*' and i + j == dd:
				ans = min(ans, dp[i][j])
	print(ans)
solve()


from math import *
from collections import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
global li, fl, fk

def rec(x, y, r, n, m, moves):
	global li, fk, fl
	if x >= n or y >= m:
		return
	if r[x][y] == '*' and (x, y) not in fk:
		fl = 1
		li.append([moves, x, y])
		fk.add((x, y))
	rec(x + 1, y, r, n, m, moves + 1)
	rec(x, y + 1, r, n, m, moves + 1)
t = 1
while t:
	t -= 1
	(n, m) = ma()
	r = []
	for i in range(n):
		a = st()
		a = list(a)
		r.append(a)
	mo = 0
	if r[0][0] == '*':
		mo += 1
		r[0][0] = '.'
	(stx, sty) = (0, 0)
	while 1:
		li = []
		fl = 0
		fk = set()
		rec(stx, sty, r, n, m, 0)
		if fl == 0:
			break
		li.sort()
		stx = li[0][1]
		sty = li[0][2]
		mo += 1
		r[stx][sty] = '.'
	print(mo)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
count = 0
i = 0
j = 0
for k in range(n + m - 1):
	if a[i][j] == '*':
		count += 1
	look_down = -1
	look_right = -1
	for q in range(i + 1, n):
		if a[q][j] == '*':
			look_down = q
	for q in range(j + 1, m):
		if a[i][q] == '*':
			look_right = q
	if look_down == -1 and look_right == -1 and (j != m - 1):
		j += 1
	elif look_down == -1 and j != m - 1:
		j += 1
	elif look_right == -1 and i != n - 1:
		i += 1
	elif look_down - i >= look_right - j and j != m - 1:
		j += 1
	else:
		i += 1
print(count)


from collections import Counter
from copy import deepcopy
from heapq import nlargest, nsmallest
import itertools
import math
import random
(H, W) = map(int, input().strip().split(' '))
cake = []
for i in range(H):
	cake.append(input().strip())
(y, x) = (0, 0)
INF = max(H, W) + 1

def decide(y, x):
	if y == H - 1:
		return (0, 1)
	if x == W - 1:
		return (1, 0)
	global cake
	(distY, distX) = (INF, INF)
	i = y + 1
	while i < H:
		if cake[i][x] == '*':
			distY = i - y
			break
		i += 1
	j = x + 1
	while j < W:
		if cake[y][j] == '*':
			distX = j - x
			break
		j += 1
	if distY == INF and distX == INF:
		return (0, 1)
	if distX <= distY:
		return (0, 1)
	return (1, 0)
cnt = 0
while y < H - 1 or x < W - 1:
	cnt += cake[y][x] == '*'
	t = decide(y, x)
	y += t[0]
	x += t[1]
cnt += cake[y][x] == '*'
print(cnt)


(h, w) = map(int, input().split())
m = []
for i in range(h):
	m += [list(input())]
(x, y) = (0, 0)
r = 0
if m[x][y] == '*':
	r += 1
while x < h - 1 or y < w - 1:
	if y < w - 1 and m[x][y + 1] == '*':
		r += 1
		y += 1
	elif x < h - 1 and m[x + 1][y] == '*':
		r += 1
		x += 1
	elif y < w - 1:
		y += 1
	else:
		x += 1
print(r)


(R, C) = [int(x) for x in input().split()]
grid = [list(input()) for r in range(R)]
count = 0
(mr, mc) = (0, 0)
if grid[mr][mc] == '*':
	count += 1
	grid[mr][mc] = '.'
while True:
	closest = (float('inf'),)
	for r in range(mr, R):
		for c in range(mc, C):
			if grid[r][c] == '*':
				closest = min(closest, (r - mr + c - mc, (r, c)))
	if closest[0] == float('inf'):
		break
	(mr, mc) = closest[1]
	grid[mr][mc] = '.'
	count += 1
print(count)


def fun(i, j):
	if i >= hw[0] or j >= hw[1]:
		return [10000, i, j]
	if a[i][j] == '*':
		return [0, i, j]
	else:
		right = fun(i + 1, j)
		down = fun(i, j + 1)
		if right[0] < down[0]:
			right[0] += 1
			return right
		else:
			down[0] += 1
			return down
(h, w) = [int(i) for i in input().split()]
hw = [h, w]
a = []
for i in range(h):
	curr = input()
	a.append([i for i in curr])
ans = 0
i = 0
j = 0
while i < h and j < w:
	ans += 1
	curr = fun(i, j)
	(i, j) = (curr[1], curr[2])
	if i < h and j < w:
		a[i][j] = '.'
print(ans - 1)


import sys
from bisect import *
from collections import deque
from copy import *
from math import *
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def dadd(d, p, val):
	if p in d:
		d[p].append(val)
	else:
		d[p] = [val]

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def bits(i, n):
	p = bin(i)[2:]
	return (n - len(p)) * '0' + p

def prec(a, pre):
	for i in a:
		pre.append(pre[-1] + i)
	pre.pop(0)

def YN(flag):
	print('YES' if flag else 'NO')

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
INF = 10 ** 18
uu = t
while t > 0:
	t -= 1
	(n, m) = mi()
	a = []
	for i in range(n):
		a.append(ii())
	c = int(a[0][0] == '*')
	i = j = 0
	while [i, j] != [n - 1, m - 1]:
		mini = 10 ** 18
		ind = [-1, -1]
		for k in range(i, n):
			for l in range(j, m):
				if a[k][l] == '*' and [k, l] != [i, j]:
					cc = k - i + l - j
					if mini > cc:
						mini = cc
						ind = [k, l]
		if ind == [-1, -1]:
			print(c)
			exit(0)
		c += 1
		(i, j) = ind
	print(c)


(h, w) = map(int, input().split())
grid = [input() for i in range(h)]
ans = x = y = 0
l = []
for i in range(h):
	for j in range(w):
		if grid[i][j] == '*':
			l.append((i, j))
while True:
	l = [i for i in l if i[0] >= x and i[1] >= y]
	if len(l) == 0:
		break
	l.sort(key=lambda x: sum(x))
	ans += 1
	(x, y) = l.pop(0)
print(ans)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	p = input()
	new = []
	for j in range(m):
		new.append(p[j])
	a.append(new)
ans = 0
x = 0
y = 0
while x != n - 1 or y != m - 1:
	if a[x][y] == '*':
		ans += 1
	if y != m - 1 and (x + 1 < n and a[x + 1][y] == '.' or (y + 1 < m and a[x][y + 1] == '*')):
		y += 1
	elif x + 1 == n:
		y += 1
	else:
		x += 1
if a[x][y] == '*':
	print(ans + 1)
else:
	print(ans)


(H, W) = map(int, input().split())
DP = [[0] * W for i in range(H)]
S = [input() for i in range(H)]
for i in range(H - 1, -1, -1):
	for j in range(W - 1, -1, -1):
		F = 0
		for k in range(1, H + W):
			for l in range(k + 1):
				(x, y) = (i + l, j + k - l)
				if x >= H or y >= W:
					continue
				if S[x][y] == '*':
					DP[i][j] = DP[x][y] + 1
					F = 1
					break
			if F:
				break
print(DP[0][0] + (S[0][0] == '*'))


(H, W) = map(int, input().split())
arr = []
for i in range(H):
	arr.append(input())
x = 0
y = 0
res = 0
if arr[0][0] == '*':
	res += 1
while not (x == W - 1 and y == H - 1):
	if x + 1 < W and arr[y][x + 1] == '*':
		x += 1
		res += 1
	elif y + 1 < H and arr[y + 1][x] == '*':
		y += 1
		res += 1
	elif x + 1 < W:
		x += 1
	else:
		y += 1
print(res)


s = []
(n, m) = map(int, input().split())
for i in range(n):
	s.append(input())
(x, y) = (0, 0)
z = 0
if s[x][y] == '*':
	z += 1
while x < n - 1 or y < m - 1:
	if x == n - 1:
		y += 1
	elif y == m - 1:
		x += 1
	elif s[x][y + 1] == '*':
		y += 1
	elif s[x + 1][y] == '*':
		x += 1
	else:
		y += 1
	if s[x][y] == '*':
		z += 1
print(z)


from string import ascii_lowercase
(n, m) = map(int, input().split())
G = [input().strip() for i in range(n)]
candy = [(i, j) for i in range(n) for j in range(m) if G[i][j] == '*']
ans = 0
(i, j) = (0, 0)
while i < n and j < m:
	ans += G[i][j] == '*'
	c = i + 1
	r = j + 1
	while r < m and G[i][r] == '.':
		r += 1
	while c < n and G[c][j] == '.':
		c += 1
	dr = r - j
	dc = c - i
	if r == m:
		dr = 10 ** 5
	if c == n:
		dc = 10 ** 5
	if dr <= dc:
		j += 1
	else:
		i += 1
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10)]
pp = [0] * 10

def SieveOfEratosthenes(n=10):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				pp[i] += 1
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = 0
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][0] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
dp = [[[0, 0] for j in range(m)] for i in range(n)]
for i in range(n - 1, -1, -1):
	for j in range(m - 1, -1, -1):
		if j == m - 1:
			dp[i][j][0] = 1000
		elif a[i][j + 1] == '*':
			dp[i][j][0] = 1
		else:
			dp[i][j][0] = min(dp[i][j + 1]) + 1
		if i == n - 1:
			dp[i][j][1] = 1000
		elif a[i + 1][j] == '*':
			dp[i][j][1] = 1
		else:
			dp[i][j][1] = min(dp[i + 1][j]) + 1
res = 0
(x, y) = (0, 0)
while x < n and y < m:
	if a[x][y] == '*':
		res += 1
	m1 = min(dp[x][y])
	if m1 == dp[x][y][0]:
		y += 1
	else:
		x += 1
print(res)


(h, w) = map(int, input().split())
a = []
for i in range(h):
	a.append(input())
i = 1
j = 1
res = 0
dir = True
while i < h or j < w:
	if a[i - 1][j - 1] == '*':
		res += 1
	if i == h:
		j += 1
	elif j == w:
		i += 1
	elif a[i][j - 1] == a[i - 1][j]:
		j += 1
	elif a[i][j - 1] == '*':
		i += 1
	else:
		j += 1
if a[h - 1][w - 1] == '*':
	res += 1
print(res)


import sys, os
if os.environ['USERNAME'] == 'kissz':
	inp = open('in.txt', 'r').readline

	def debug(*args):
		print(*args, file=sys.stderr)
else:
	inp = sys.stdin.readline

	def debug(*args):
		pass
(h, w) = map(int, inp().split())
M = []
for _ in range(h):
	M += [inp().strip()]
x = y = 0
cnt = 0
Q = [(x, y)]
while x < h - 1 or y < w - 1:
	while Q:
		(x, y) = Q.pop(0)
		if M[x][y] == '*' or (x >= h - 1 and y >= w - 1):
			break
		if y < w - 1:
			Q.append((x, y + 1))
		if x < h - 1:
			Q.append((x + 1, y))
	cnt += int(M[x][y] == '*')
	Q = []
	if y < w - 1:
		Q.append((x, y + 1))
	if x < h - 1:
		Q.append((x + 1, y))
print(cnt)


(n, m) = map(int, input().split())
anime = []
for i in range(n):
	s = input()
	anime.append(s)
x = 0
y = 0
ans = 0
if anime[0][0] == '*':
	ans += 1
while True:
	a = n
	b = m
	for i in range(x, n):
		for j in range(y, m):
			if (i != x or j != y) and anime[i][j] == '*' and (a + b > i + j):
				a = i
				b = j
	if a == n:
		break
	ans += 1
	x = a
	y = b
print(ans)


(H, W) = map(int, input().split())
rows = []
for _ in range(H):
	rows.append(input())
ans = 0
(x, y) = (0, 0)
while True:
	ans += rows[x][y] == '*'
	if (x, y) == (H - 1, W - 1):
		break
	(nx, ny) = (None, None)
	mindist = float('inf')
	for i in range(x, H):
		for j in range(y, W):
			if rows[i][j] == '.':
				continue
			dist = abs(i - x) + abs(j - y)
			if not dist:
				continue
			if dist < mindist:
				mindist = dist
				nx = i
				ny = j
	if mindist == float('inf'):
		break
	x = nx
	y = ny
print(ans)