There is a magic room in a homestead. The room is paved with H × W tiles. There are five different tiles:

* Tile with a east-pointing arrow
* Tile with a west-pointing arrow
* Tile with a south-pointing arrow
* Tile with a north-pointing arrow
* Tile with nothing



Once a person steps onto a tile which has an arrow, the mystic force makes the person go to the next tile pointed by the arrow. If the next tile has an arrow, the person moves to the next, ans so on. The person moves on until he/she steps onto a tile which does not have the arrow (the tile with nothing). The entrance of the room is at the northwest corner.

Your task is to write a program which simulates the movement of the person in the room. The program should read strings which represent the room and print the last position of the person.

The input represents the room as seen from directly above, and up, down, left and right side of the input correspond to north, south, west and east side of the room respectively. The horizontal axis represents x-axis (from 0 to W-1, inclusive) and the vertical axis represents y-axis (from 0 to H-1, inclusive). The upper left tile corresponds to (0, 0).

The following figure shows an example of the input:


10 10
>>>v..>>>v
...v..^..v
...>>>^..v
.........v
.v<<<<...v
.v...^...v
.v...^<<<<
.v........
.v...^....
.>>>>^....


Characters represent tiles as follows:


'>': Tile with a east-pointing arrow
'<': Tile with a west-pointing arrow
'^': Tile with a north-pointing arrow
'v': Tile with a south-pointing arrow
'.': Tile with nothing


If the person goes in cycles forever, your program should print "LOOP". You may assume that the person never goes outside of the room.



Input

The input consists of multiple datasets. The input ends with a line which contains two 0. Each dataset consists of:


H W
H lines where each line contains W characters


You can assume that 0 < W, H < 101.

Output

For each dataset, print the coordinate (X, Y) of the person or "LOOP" in a line. X and Y should be separated by a space.

Examples

Input

10 10
>>>v..>>>v
...v..^..v
>>>>>>^..v
.........v
.v


Output

5 7
LOOP


Input

10 10
>>>v..>>>v
...v..^..v
>>>>>>^..v
.........v
.v<<<<...v
.v.v.^...v
.v.v.^<<<<
.v.v.....v
.v...^...v
.>>>>^....
6 10
>>>>>>>>>v
.........v
.........v
>>>>v....v
^...v....v
^<<<<<<<<<
0 0


Output

5 7
LOOP

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
while True:
	(h, w) = map(int, input().split())
	if (h, w) == (0, 0):
		break
	l = []
	for i in range(h):
		l.append(input())
	(x, y) = (0, 0)
	l1 = []
	while True:
		if (x, y) in l1:
			print('LOOP')
			break
		l1.append((x, y))
		pos = l[y][x]
		if pos == '.':
			print(x, y)
			break
		elif pos == '<':
			x -= 1
		elif pos == '>':
			x += 1
		elif pos == '^':
			y -= 1
		elif pos == 'v':
			y += 1


while 1:
	(H, W) = map(int, input().split())
	if H == 0:
		break
	m = [input() for _ in [0] * H]
	y = x = 0
	for _ in range(H * W):
		(u, v) = (x, y)
		c = m[y][x]
		if c == '>':
			x += 1
		if c == 'v':
			y += 1
		if c == '<':
			x -= 1
		if c == '^':
			y -= 1
		if c == '.':
			print(x, y)
			break
	else:
		print('LOOP')


def judgement(tmp, matrix):
	judge = []
	(x, y) = (0, 0)
	while True:
		if [x, y] in judge:
			print('LOOP')
			break
		judge.append([x, y])
		if tmp[x][y] == '>':
			y += 1
		elif tmp[x][y] == '<':
			y -= 1
		elif tmp[x][y] == '^':
			x -= 1
		elif tmp[x][y] == 'v':
			x += 1
		else:
			print(y, x)
			break
while True:
	(H, W) = map(int, input().split())
	if H == W == 0:
		break
	matrix = [[0 for i in range(W)] for i in range(H)]
	tmp = []
	for i in range(H):
		hhh = list(map(str, input()))
		tmp.append(hhh)
	judgement(tmp, matrix)


import sys
readline = sys.stdin.readline
write = sys.stdout.write
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
df = '<^>v'.find

def solve():
	(H, W) = map(int, readline().split())
	if H == 0:
		return False
	MP = [readline().strip() for i in range(H)]
	x = y = 0
	used = [[0] * W for i in range(H)]
	used[0][0] = 1
	while 1:
		i = df(MP[y][x])
		if i == -1:
			write('%d %d\n' % (x, y))
			return True
		(dx, dy) = dd[i]
		x += dx
		y += dy
		if used[y][x]:
			write('LOOP\n')
			return True
		used[y][x] = 1
while solve():
	...


while True:
	(h, w) = map(int, input().split())
	if (h, w) == (0, 0):
		break
	roop = [[False for i in range(w)] for j in range(h)]
	s = [input() for _ in range(h)]
	(x, y) = (0, 0)
	jud = True
	while s[y][x] != '.':
		if roop[y][x]:
			print('LOOP')
			jud = False
			break
		roop[y][x] = True
		if s[y][x] == '>':
			x += 1
		elif s[y][x] == '<':
			x -= 1
		elif s[y][x] == 'v':
			y += 1
		else:
			y -= 1
	if jud:
		print(x, y)


dp = [[''] * 100 for i in range(100)]
while 1:
	try:
		(h, w) = (int(x) for x in input().split())
		if w == 0:
			break
		s = ''
		x = y = 0
		ans = 'LOOP'
		for i in range(0, h):
			s += input()
		for i in range(0, h):
			for j in range(0, w):
				dp[i][j] = s[i * w + j]
		while 1:
			c = dp[y][x]
			dp[y][x] = 'd'
			if c == '>':
				x += 1
			if c == 'v':
				y += 1
			if c == '^':
				y -= 1
			if c == '<':
				x -= 1
			if c == 'd':
				break
			if c == '.':
				ans = str(x) + ' ' + str(y)
				break
		print(ans)
	except EOFError:
		break


def run_magic_tiles(magic_tiles, past_matrix):
	(i, j) = (0, 0)
	while True:
		move = {'^': (-1, 0), 'v': (1, 0), '<': (0, -1), '>': (0, 1), '.': (-1, -1)}.get(magic_tiles[i][j])
		if move[0] == -1 and move[1] == -1:
			return (j, i)
		else:
			i += move[0]
			j += move[1]
			if past_matrix[i][j]:
				return 'LOOP'
			past_matrix[i][j] = 1

def main():
	while True:
		(c, r) = map(int, input().split(' '))
		if c == 0 and r == 0:
			break
		past_matrix = [[0 for _ in range(r)] for _ in range(c)]
		tiles = []
		for _ in range(c):
			tiles.append(list(input()))
		res = run_magic_tiles(tiles, past_matrix)
		print('LOOP' if res == 'LOOP' else '%d %d' % (res[0], res[1]))
main()


import sys
import math

class mymath:
	pi = 3.141592653589793

	def pnum_eratosthenes(self, n):
		ptable = [0 for i in range(n + 1)]
		plist = []
		for i in range(2, n + 1):
			if ptable[i] == 0:
				plist.append(i)
				for j in range(i + i, n + 1, i):
					ptable[j] = 1
		return plist

	def pnum_check(self, n):
		if n == 1:
			return False
		elif n == 2:
			return True
		else:
			for x in range(2, n):
				if n % x == 0:
					return False
			return True

	def gcd(self, a, b):
		if b == 0:
			return a
		return self.gcd(b, a % b)

	def lcm(self, a, b):
		return a * b // self.gcd(a, b)

	def mul(self, A, B):
		ans = []
		for a in A:
			c = 0
			for (j, row) in enumerate(a):
				c += row * B[j]
			ans.append(c)
		return ans
mymath = mymath()

class output:

	def list(self, l):
		l = list(l)
		for (i, num) in enumerate(l):
			print(num, end='')
			if i != len(l) - 1:
				print(' ', end='')
		print()
output = output()

def is_integer(n):
	try:
		float(n)
	except ValueError:
		return False
	else:
		return float(n).is_integer()

def dist(A, B):
	d = 0
	for i in range(len(A)):
		d += (A[i] - B[i]) ** 2
	d = d ** (1 / 2)
	return d

def get_input():
	N = []
	while True:
		try:
			N.append(input())
		except EOFError:
			break
	return N
while True:
	(H, W) = [int(x) for x in input().split()]
	if H == 0 and W == 0:
		break
	M = []
	for i in range(H):
		M.append(input())
	root = []
	x = 0
	y = 0
	while True:
		if M[y][x] == '>':
			x += 1
		elif M[y][x] == '<':
			x -= 1
		elif M[y][x] == 'v':
			y += 1
		elif M[y][x] == '^':
			y -= 1
		if M[y][x] == '.':
			print(x, y, sep=' ')
			break
		if (x, y) in root:
			print('LOOP')
			break
		root.append((x, y))


while True:
	(h, w) = map(int, input().split())
	if h == 0:
		break
	t_list = []
	for i in range(h):
		t_list.append(input())
	p = [0, 0]
	p_passed = []
	while True:
		t = t_list[p[1]][p[0]]
		if t == '>':
			p[0] += 1
		elif t == '<':
			p[0] -= 1
		elif t == '^':
			p[1] -= 1
		elif t == 'v':
			p[1] += 1
		else:
			print(p[0], p[1])
			break
		if p in p_passed:
			print('LOOP')
			break
		p_passed.append(p[:])


M = ['^', '<', 'v', '>']
while True:
	n = list(map(int, input().split()))
	if n == [0, 0]:
		break
	D = {}
	for r in range(n[0]):
		s = 0
		C = input()
		for c in C:
			D[r, s] = [c, 0]
			s += 1
	now = [0, 0]
	while True:
		if D[tuple(now)][1] == 0:
			D[tuple(now)][1] += 1
			if D[tuple(now)][0] == '.':
				now.reverse()
				break
			else:
				m = M.index(D[tuple(now)][0])
				now[m % 2] += m // 2 * 2 - 1
		else:
			now = ['LOOP']
			break
	print(' '.join(list(map(str, now))))


info = {'>': (0, 1), '<': (0, -1), '^': (-1, 0), 'v': (1, 0), '.': (-1, -1)}
while True:
	(H, W) = map(int, input().split())
	if H == 0:
		break
	tiles = [input() for _ in range(H)]
	i = j = 0
	for _ in range(H * W):
		(a, b) = info[tiles[i][j]]
		if a == b == -1:
			print(j, i)
			break
		i += a
		j += b
	else:
		print('LOOP')


while True:
	(h, w) = map(int, input().split())
	if not h:
		break
	mp = [input() for _ in range(h)]
	visited = [[False for _ in range(w)] for _ in range(h)]
	(x, y) = (0, 0)
	while True:
		if visited[y][x]:
			print('LOOP')
			break
		tile = mp[y][x]
		if tile == '.':
			print(x, y)
			break
		visited[y][x] = True
		if tile == '>':
			x += 1
		elif tile == '<':
			x -= 1
		elif tile == '^':
			y -= 1
		else:
			y += 1


STATE = {'NOTHING': '.', 'LOOP': 'E'}
DIRECT = {'>': [0, 1], '<': [0, -1], '^': [-1, 0], 'v': [1, 0]}
output = []
while True:
	(width, height) = [int(item) for item in input().split(' ')]
	if width == 0 and height == 0:
		break
	tiles = []
	for lp in range(width):
		splits = [item for item in input()]
		tiles.append(splits)
	(row, col) = (0, 0)
	while True:
		if tiles[row][col] == STATE['NOTHING']:
			output.append(str(col) + ' ' + str(row))
			break
		elif tiles[row][col] == STATE['LOOP']:
			output.append('LOOP')
			break
		for key in DIRECT:
			if tiles[row][col] == key:
				tiles[row][col] = STATE['LOOP']
				row += DIRECT[key][0]
				col += DIRECT[key][1]
				break
print('\n'.join(output))


import sys

class MagicalTiles:

	def __init__(self, data):
		self.map = data[:]
		self.pos = (0, 0)
		self.path = [(0, 0)]
		self.mark = self.map[0][0]
		self.loop = False

	def move(self):
		(x, y) = (self.pos[0], self.pos[1])
		self.mark = self.map[y][x]
		if self.mark == '>':
			x += 1
		elif self.mark == '<':
			x -= 1
		elif self.mark == '^':
			y -= 1
		elif self.mark == 'v':
			y += 1
		if self.mark != '.' and (x, y) in self.path:
			self.loop = True
		else:
			self.path.append((x, y))
		self.pos = (x, y)

def main(args):
	while True:
		(h, w) = [int(x) for x in input().split(' ')]
		if h == 0 and w == 0:
			break
		data = [input() for _ in range(h)]
		m = MagicalTiles(data)
		while m.mark != '.':
			m.move()
			if m.loop:
				break
		if m.loop:
			print('LOOP')
		else:
			print(m.pos[0], m.pos[1])
main(sys.argv[1:])


while True:
	(h, w) = [int(x) for x in input().split()]
	if h == 0 and w == 0:
		break
	T = [[0] * w for x in range(h)]
	M = []
	for _ in range(h):
		M.append(list(input()))
	i = 0
	j = 0
	loop = 0
	while True:
		if T[i][j] > 0:
			loop += 1
			break
		else:
			T[i][j] += 1
		if M[i][j] == '.':
			break
		elif M[i][j] == '>':
			j += 1
		elif M[i][j] == '<':
			j -= 1
		elif M[i][j] == '^':
			i -= 1
		else:
			i += 1
	if loop > 0:
		print('LOOP')
	else:
		print(j, i)


def run_magic_tiles(magic_tiles, past_matrix):

	def move_up(x, y):
		return (x - 1, y)

	def move_down(x, y):
		return (x + 1, y)

	def move_left(x, y):
		return (x, y - 1)

	def move_right(x, y):
		return (x, y + 1)

	def goal():
		return (-1, -1)
	(i, j) = (0, 0)
	while True:
		res = {'^': move_up(i, j), 'v': move_down(i, j), '<': move_left(i, j), '>': move_right(i, j), '.': goal()}.get(magic_tiles[i][j])
		if res[0] == -1 and res[1] == -1:
			return (j, i)
		else:
			(i, j) = res
			if past_matrix[i][j]:
				return 'LOOP'
			past_matrix[i][j] = 1

def main():
	while True:
		(c, r) = map(int, input().split(' '))
		if c == 0 and r == 0:
			break
		past_matrix = [[0 for _ in range(r)] for _ in range(c)]
		tiles = []
		for _ in range(c):
			tiles.append(list(input()))
		res = run_magic_tiles(tiles, past_matrix)
		print('LOOP' if res == 'LOOP' else '%d %d' % (res[0], res[1]))
main()


import sys
import os
for s in sys.stdin:
	(H, W) = map(int, s.split())
	if H == W == 0:
		break
	M = []
	for i in range(H):
		s = input().strip()
		M.append(s)
	is_loop = False
	x = 0
	y = 0
	walk = 0
	while True:
		mark = M[y][x]
		walk += 1
		if walk > H * W:
			is_loop = True
			break
		if mark == '.':
			break
		if mark == '>':
			x += 1
		elif mark == 'v':
			y += 1
		elif mark == '^':
			y -= 1
		elif mark == '<':
			x -= 1
	if is_loop:
		print('LOOP')
	else:
		print(x, y)


for a in iter(input, '0 0'):
	(H, W) = map(int, a.split())
	m = [input() for _ in [0] * H]
	y = x = 0
	for _ in range(H * W):
		c = m[y][x]
		if '>' == c:
			x += 1
		if 'v' == c:
			y += 1
		if '<' == c:
			x -= 1
		if '^' == c:
			y -= 1
		if '.' == c:
			print(x, y)
			break
	else:
		print('LOOP')


while 1:
	(h, w) = map(int, input().split())
	if w == 0:
		break
	a = [input() for _ in [0] * h]
	b = [(0, 0)]
	i = j = 0
	while a[i][j] != '.':
		if a[i][j] == '>':
			j += 1
		elif a[i][j] == '<':
			j -= 1
		elif a[i][j] == 'v':
			i += 1
		elif a[i][j] == '^':
			i -= 1
		if (i, j) in b:
			print('LOOP')
			break
		b += [(i, j)]
	else:
		print(j, i)


while True:
	HW = list(map(int, input().split()))
	(H, W) = (HW[0], HW[1])
	if H == 0 and W == 0:
		break
	tiles = [input() for i in range(H)]
	(i, j, count) = (0, 0, 0)
	while True:
		tile = tiles[i][j]
		if count >= H * W:
			print('LOOP')
			break
		if tile == '>':
			if W > j:
				j += 1
			else:
				print(j, i)
				break
		elif tile == '<':
			if j > 0:
				j -= 1
			else:
				print(j, i)
				break
		elif tile == '^':
			if i > 0:
				i -= 1
			else:
				print(j, i)
				break
		elif tile == 'v':
			if H > i:
				i += 1
			else:
				print(j, i)
				break
		else:
			print(j, i)
			break
		count += 1


while True:
	(ny, nx) = map(int, input().split())
	if nx == 0 and ny == 0:
		break
	dic = {'>': [1, 0], '<': [-1, 0], '^': [0, -1], 'v': [0, 1], '.': [0, 0]}
	poshist = []
	ma = [input() for i in range(ny)]
	(px, py) = (0, 0)
	poshist.append([px, py])
	while True:
		px += dic[ma[py][px]][0]
		py += dic[ma[py][px]][1]
		if [px, py] in poshist:
			poshist.append([px, py])
			break
		else:
			poshist.append([px, py])
	if poshist[-1] == poshist[-2]:
		print(poshist[-1][0], poshist[-1][1])
	else:
		print('LOOP')


while True:
	(x, y) = map(int, input().split())
	if x == 0 and y == 0:
		break
	A = []
	for _ in range(x):
		line = list(input())
		A.append(line)
	ans = []
	W = 0
	H = 0
	s = A[H][W]
	while True:
		if s == '>':
			W += 1
		elif s == '<':
			W -= 1
		elif s == '^':
			H -= 1
		elif s == 'v':
			H += 1
		else:
			print(W, H)
			break
		s = A[H][W]
		if [H, W] in ans:
			print('LOOP')
			break
		else:
			ans.append([H, W])


while True:
	(H, W) = list(map(int, input().split()))
	if (H, W) == (0, 0):
		break
	(x, y) = (0, 0)
	log = [(x, y)]
	floor = [list(input()) for i in range(H)]
	while True:
		if floor[y][x] == '.':
			print(x, y)
			break
		elif floor[y][x] == '>':
			log.append((x, y))
			x += 1
		elif floor[y][x] == '<':
			log.append((x, y))
			x -= 1
		elif floor[y][x] == '^':
			log.append((x, y))
			y -= 1
		elif floor[y][x] == 'v':
			log.append((x, y))
			y += 1
		if (x, y) in log:
			print('LOOP')
			break


(X, Y) = map(int, input().split())
while X != 0 and Y != 0:
	Slist = []
	for i in range(X):
		S = list(map(str, input()))
		Slist.append(S)
	store = [(0, 0)]
	x = 0
	y = 0
	while True:
		if Slist[x][y] == '>':
			y += 1
		elif Slist[x][y] == '<':
			y -= 1
		elif Slist[x][y] == 'v':
			x += 1
		elif Slist[x][y] == '^':
			x -= 1
		if Slist[x][y] == '.':
			loop = 0
			break
		if (x, y) in store:
			loop = 1
			break
		store.append((x, y))
	if loop == 1:
		print('LOOP')
	elif loop == 0:
		print(y, x)
	(X, Y) = map(int, input().split())


import sys
while True:
	(H, W) = [int(i) for i in input().split(' ')]
	if H == 0 and W == 0:
		break
	Tiles = []
	for i in range(H):
		Tiles.append(input())
	step = 0
	x = 0
	y = 0
	while True:
		if Tiles[y][x] == '>':
			x += 1
		elif Tiles[y][x] == '<':
			x -= 1
		elif Tiles[y][x] == '^':
			y -= 1
		elif Tiles[y][x] == 'v':
			y += 1
		step += 1
		if Tiles[y][x] == '.':
			print(x, y)
			break
		if step > H * W + 5:
			print('LOOP')
			break


while True:
	(h, w) = map(int, input().split())
	if h == w == 0:
		break
	maze = [input() for i in range(h)]
	now_x = now_y = 0
	is_used = [[False for j in range(w)] for i in range(h)]
	is_used[0][0] = True
	while True:
		now = maze[now_y][now_x]
		if now == '>':
			now_x += 1
		elif now == '<':
			now_x -= 1
		elif now == 'v':
			now_y += 1
		elif now == '^':
			now_y -= 1
		else:
			print(now_x, now_y)
			break
		if is_used[now_y][now_x]:
			print('LOOP')
			break
		is_used[now_y][now_x] = True


(H, W) = (1, 1)
while True:
	(posX, posY) = (0, 0)
	(H, W) = map(int, input().split())
	if (H == W == 0) == True:
		break
	tile = [[False for i in range(W)] for j in range(H)]
	tileinfo = [['' for i in range(W)] for j in range(H)]
	for i in range(H):
		tileinfo[i] = input().rstrip()
	while True:
		if tile[posY][posX] == True:
			print('LOOP')
			break
		else:
			tile[posY][posX] = True
		if tileinfo[posY][posX] == '>':
			posX += 1
		elif tileinfo[posY][posX] == '<':
			posX -= 1
		elif tileinfo[posY][posX] == 'v':
			posY += 1
		elif tileinfo[posY][posX] == '^':
			posY -= 1
		elif tileinfo[posY][posX] == '.':
			print('{} {}'.format(posX, posY))
			break


while True:
	(h, w) = list(map(int, input().split()))
	if h == 0:
		break
	a = [0] * h
	for r in range(h):
		a[r] = list(input())
	r = c = 0
	while True:
		k = a[r][c]
		a[r][c] = '#'
		if k == '#':
			print('LOOP')
			break
		elif k == '>':
			c += 1
		elif k == '<':
			c -= 1
		elif k == '^':
			r -= 1
		elif k == 'v':
			r += 1
		elif k == '.':
			print(c, r)
			break


while True:
	try:
		(H, W) = map(int, input().split())
		if H == W and H == 0:
			break
	except:
		break
	(x, y) = (0, 0)
	room = []
	move_his = []
	flg = False
	for i in range(H):
		room.append([t for t in input()])
	while room[y][x] != '.':
		if room[y][x] == '>':
			x += 1
		elif room[y][x] == '<':
			x -= 1
		elif room[y][x] == '^':
			y -= 1
		elif room[y][x] == 'v':
			y += 1
		if [x, y] in move_his:
			flg = True
			break
		move_his.append([x, y])
	if flg:
		print('LOOP')
	else:
		print(x, y)


for a in iter(input, '0 0'):
	m = [input() for _ in [0] * int(a.split()[0])]
	y = x = 0
	s = {(0, 0)}
	while '.' != m[y][x]:
		(u, v) = (x, y)
		c = m[y][x]
		if c == '>':
			x += 1
		if c == 'v':
			y += 1
		if c == '<':
			x -= 1
		if c == '^':
			y -= 1
		if (x, y) in s:
			print('LOOP')
			break
		else:
			s |= {(x, y)}
	else:
		print(x, y)


size = input()
while size != '0 0':
	tile = []
	for i in range(0, int(size.split(' ')[0])):
		tilestr = []
		inp = input()
		for j in range(0, int(size.split(' ')[1])):
			tilestr.append(inp[j:j + 1])
		tile.append(tilestr)
		isVisited = []
		for i in range(0, len(tile)):
			isIdxVisited = []
			for j in range(0, len(tile[i])):
				isIdxVisited.append(False)
			isVisited.append(isIdxVisited)
	currentIdx = [0, 0]
	while True:
		if isVisited[currentIdx[1]][currentIdx[0]] == True:
			print('LOOP')
			break
		isVisited[currentIdx[1]][currentIdx[0]] = True
		if tile[currentIdx[1]][currentIdx[0]] == '^':
			currentIdx[1] -= 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == 'v':
			currentIdx[1] += 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == '<':
			currentIdx[0] -= 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == '>':
			currentIdx[0] += 1
			continue
		elif tile[currentIdx[1]][currentIdx[0]] == '.':
			print(str(currentIdx[0]) + ' ' + str(currentIdx[1]))
			break
	size = input()


for a in iter(input, '0 0'):
	m = [input() for _ in [0] * int(a.split()[0])]
	y = x = 0
	s = {(0, 0)}
	while 1:
		c = m[y][x]
		if '>' == c:
			x += 1
		if 'v' == c:
			y += 1
		if '<' == c:
			x -= 1
		if '^' == c:
			y -= 1
		if '.' == c:
			print(x, y)
			break
		if (x, y) in s:
			print('LOOP')
			break
		else:
			s |= {(x, y)}


import sys, math, os
PYDEV = os.environ.get('PYDEV')
if PYDEV == 'True':
	sys.stdin = open('sample-input.txt', 'rt')

def magical_tiles(H, W, tiles):
	moves = {'>': [0, 1], '<': [0, -1], '^': [-1, 0], 'v': [1, 0]}
	visited = set()
	(row, col) = (0, 0)
	while True:
		if tiles[row][col] == '.':
			print(col, row)
			return
		if (row, col) in visited:
			print('LOOP')
			return
		visited.add((row, col))
		direction = tiles[row][col]
		row += moves[direction][0]
		col += moves[direction][1]
while True:
	(H, W) = [int(_) for _ in input().split()]
	if H == W == 0:
		break
	tiles = [[_ for _ in input().strip()] for __ in range(H)]
	magical_tiles(H, W, tiles)


import sys
import math

def decide_move(x, y, tile, check):
	if tile == '<':
		y -= 1
		check[x][y] += 1
		return (x, y, check)
	elif tile == '>':
		y += 1
		check[x][y] += 1
		return (x, y, check)
	elif tile == '^':
		x -= 1
		check[x][y] += 1
		return (x, y, check)
	else:
		x += 1
		check[x][y] += 1
		return (x, y, check)
while True:
	(h, w) = map(int, input().split())
	if h == 0:
		break
	tile_map = []
	for i in range(h):
		tile_map.append(input())
	check = [[0 for i in range(w)] for j in range(h)]
	check[0][0] = 1
	x = 0
	y = 0
	status = 0
	while True:
		if tile_map[x][y] == '.':
			status = 1
			print(y, x)
			break
		(x, y, check) = decide_move(x, y, tile_map[x][y], check)
		if check[x][y] > 1:
			status = 1
			print('LOOP')
			break


while True:
	(H, W) = map(int, input().split())
	if H == 0 and W == 0:
		break
	roop = 'OFF'
	Tile = [list(input()) for j in range(H)]
	cursol_H = 0
	cursol_W = 0
	roop = 'OFF'
	while True:
		if Tile[cursol_H][cursol_W] == '>':
			Tile[cursol_H][cursol_W] = '/'
			cursol_W += 1
		elif Tile[cursol_H][cursol_W] == 'v':
			Tile[cursol_H][cursol_W] = '/'
			cursol_H += 1
		elif Tile[cursol_H][cursol_W] == '<':
			Tile[cursol_H][cursol_W] = '/'
			cursol_W -= 1
		elif Tile[cursol_H][cursol_W] == '^':
			Tile[cursol_H][cursol_W] = '/'
			cursol_H -= 1
		elif Tile[cursol_H][cursol_W] == '/':
			roop = 'ON'
			break
		else:
			break
	if roop == 'ON':
		print('LOOP')
	else:
		print(cursol_W, cursol_H)


import sys

def solve():
	while True:
		m = []
		(h, w) = map(int, sys.stdin.readline().split(' '))
		if h == 0 and w == 0:
			break
		for r in range(h):
			m.append(list(sys.stdin.readline()[:-1]))
		r = 0
		c = 0
		while m[r][c] != '*':
			if m[r][c] == '>':
				m[r][c] = '*'
				c += 1
			elif m[r][c] == '<':
				m[r][c] = '*'
				c -= 1
			elif m[r][c] == 'v':
				m[r][c] = '*'
				r += 1
			elif m[r][c] == '^':
				m[r][c] = '*'
				r -= 1
			elif m[r][c] == '.':
				break
		if m[r][c] == '*':
			print('LOOP')
		else:
			print('{} {}'.format(c, r))
solve()


dir = {'>': (0, 1), '<': (0, -1), 'v': (1, 0), '^': (-1, 0)}

def solve(h, w, tiles, visited):
	(x, y) = (0, 0)
	while True:
		if tiles[y][x] == '.':
			print(x, y)
			break
		if not visited[y][x]:
			print('LOOP')
			break
		visited[y][x] = False
		(next_y, next_x) = dir[tiles[y][x]]
		x += next_x
		y += next_y
	return
while True:
	inputs = input().split()
	h = int(inputs[0])
	w = int(inputs[1])
	if h == 0 and w == 0:
		break
	visited = [[True for i in range(w)] for j in range(h)]
	tiles = ['' for i in range(h)]
	for i in range(h):
		tiles[i] = input()
	solve(h, w, tiles, visited)


while True:
	(H, W) = list(map(int, input().split()))
	if H == 0 and W == 0:
		break
	else:
		a = list((input() for i in range(H)))
		visitedlist = []
		h = 0
		w = 0
		while True:
			if [h, w] not in visitedlist:
				visitedlist.append([h, w])
				if a[h][w] == '>':
					w += 1
				if a[h][w] == '<':
					w -= 1
				if a[h][w] == '^':
					h -= 1
				if a[h][w] == 'v':
					h += 1
				if a[h][w] == '.':
					print(w, h)
					break
			else:
				print('LOOP')
				break


for a in iter(input, '0 0'):
	(H, W) = map(int, a.split())
	m = [input() for _ in [0] * H]
	y = x = 0
	for _ in range(H * W):
		(u, v) = (x, y)
		c = m[y][x]
		if c == '>':
			x += 1
		if c == 'v':
			y += 1
		if c == '<':
			x -= 1
		if c == '^':
			y -= 1
		if c == '.':
			print(x, y)
			break
	else:
		print('LOOP')


while True:
	(H, W) = map(int, input().split())
	if H == W == 0:
		break
	tile = [list(input()) for i in range(H)]
	x = y = 0
	while True:
		tmp = tile[y][x]
		tile[y][x] = '*'
		if tmp == '*':
			print('LOOP')
			break
		elif tmp == '>':
			x += 1
		elif tmp == '<':
			x -= 1
		elif tmp == '^':
			y -= 1
		elif tmp == 'v':
			y += 1
		elif tmp == '.':
			print(x, y)
			break


import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 1e-09
sys.setrecursionlimit(100000)
North = 0
East = 1
South = 2
West = 3
DICT = {'^': North, '>': East, 'v': South, '<': West}
while True:
	(H, W) = map(int, input().split())
	if H == 0 and W == 0:
		break
	base_map = [input() for _ in range(H)]
	check = [[False] * W for row in range(H)]
	row = 0
	col = 0
	while True:
		if base_map[row][col] == '.':
			print('%d %d' % (col, row))
			break
		else:
			if check[row][col] == True:
				print('LOOP')
				break
			check[row][col] = True
			tmp_dir = DICT[base_map[row][col]]
			if tmp_dir == North:
				row -= 1
			elif tmp_dir == East:
				col += 1
			elif tmp_dir == South:
				row += 1
			else:
				col -= 1


import sys
from pprint import pprint

def main():
	for line in sys.stdin:
		(H, W) = map(int, line.split())
		if H == 0 and W == 0:
			break
		else:
			t = []
			for _ in range(H):
				t.append(list(input()))
			(x, y) = (0, 0)
			cnt = 0
			while True:
				cnt += 1
				if t[x][y] == '>':
					y += 1
				elif t[x][y] == 'v':
					x += 1
				elif t[x][y] == '<':
					y -= 1
				elif t[x][y] == '^':
					x -= 1
				elif t[x][y] == '.':
					f = 0
					break
				if cnt > H * W:
					f = 1
					break
				else:
					pass
			if f == 0:
				print(y, x)
			elif f == 1:
				print('LOOP')
main()


def search(table, visited, x, y):
	if visited[x][y]:
		print('LOOP')
		return
	visited[x][y] = True
	if table[x][y] == '>':
		search(table, visited, x, y + 1)
	elif table[x][y] == 'v':
		search(table, visited, x + 1, y)
	elif table[x][y] == '^':
		search(table, visited, x - 1, y)
	elif table[x][y] == '<':
		search(table, visited, x, y - 1)
	elif table[x][y] == '.':
		print(y, x)
		return
while True:
	(X, Y) = [int(i) for i in input().split()]
	if X == 0 and Y == 0:
		break
	table = [[0 for i in range(Y)] for j in range(X)]
	visited = [[False for i in range(Y)] for j in range(X)]
	for i in range(X):
		L = input()
		for j in range(Y):
			table[i][j] = L[j]
	search(table, visited, 0, 0)


while 1:
	(h, w) = map(int, input().split())
	if h == 0 and w == 0:
		break
	mat = []
	for _ in range(h):
		mat.append(list(input()))
	x = 0
	y = 0
	cnt = 0
	flag = False
	while mat[x][y] != '.':
		cnt += 1
		if mat[x][y] == '>':
			y += 1
		elif mat[x][y] == '<':
			y -= 1
		elif mat[x][y] == '^':
			x -= 1
		elif mat[x][y] == 'v':
			x += 1
		if cnt == 10 ** 4:
			flag = True
			break
	if flag:
		print('LOOP')
	else:
		print(y, x)


while 1:
	(H, W) = map(int, input().split())
	if H == W == 0:
		break
	maze = []
	root = []
	x = 0
	y = 0
	for i in range(H):
		maze.append(list(input()))
	while 1:
		if maze[y][x] == '>':
			x += 1
		elif maze[y][x] == '<':
			x -= 1
		elif maze[y][x] == '^':
			y -= 1
		elif maze[y][x] == 'v':
			y += 1
		else:
			print(x, y)
			break
		if x + y * W in root:
			print('LOOP')
			break
		root.append(x + y * W)


def move(Tiles_map, x, y, Loop_ch):
	if [x, y] in Loop_ch:
		print('LOOP')
		return
	else:
		Loop_ch.append([x, y])
	if Tile_map[x][y] == '.':
		print(str(y) + ' ' + str(x))
		return
	elif Tile_map[x][y] == '>':
		move(Tiles_map, x, y + 1, Loop_ch)
	elif Tile_map[x][y] == '<':
		move(Tiles_map, x, y - 1, Loop_ch)
	elif Tile_map[x][y] == 'v':
		move(Tiles_map, x + 1, y, Loop_ch)
	elif Tile_map[x][y] == '^':
		move(Tiles_map, x - 1, y, Loop_ch)
while True:
	Tile_map = []
	Loop_ch = []
	(H, W) = map(int, input().split())
	if H == 0 and W == 0:
		break
	for i in range(H):
		Tiles = input()
		Tiles = list(str(Tiles))
		Tile_map.append(Tiles)
	ans = move(Tile_map, 0, 0, Loop_ch)


for a in iter(input, '0 0'):
	m = [input() for _ in [0] * int(a.split()[0])]
	y = x = 0
	s = {(0, 0)}
	while '.' != m[y][x]:
		c = m[y][x]
		if '>' == c:
			x += 1
		if 'v' == c:
			y += 1
		if '<' == c:
			x -= 1
		if '^' == c:
			y -= 1
		if (x, y) in s:
			print('LOOP')
			break
		else:
			s |= {(x, y)}
	else:
		print(x, y)


def ans(m):
	h = 0
	w = 0
	pas = []
	while True:
		if m[h][w] == '>':
			w += 1
		elif m[h][w] == '<':
			w -= 1
		elif m[h][w] == '^':
			h -= 1
		elif m[h][w] == 'v':
			h += 1
		elif m[h][w] == '.':
			return '{0} {1}'.format(w, h)
		if (h, w) in pas:
			return 'LOOP'
		else:
			pas.append((h, w))
while True:
	[h, w] = map(int, input().split())
	if h == 0 and w == 0:
		break
	m = []
	for _ in range(h):
		m.append(input())
	res = ans(m)
	print(res)


def magicall(tiles, a, b):
	point = tiles[a][b]
	if point == '.':
		return (a, b)
	elif point == '>':
		tiles[a][b] = '0'
		return magicall(tiles, a, b + 1)
	elif point == '<':
		tiles[a][b] = '0'
		return magicall(tiles, a, b - 1)
	elif point == '^':
		tiles[a][b] = '0'
		return magicall(tiles, a - 1, b)
	elif point == 'v':
		tiles[a][b] = '0'
		return magicall(tiles, a + 1, b)
	elif point == '0':
		return 'LOOP'
while 1:
	(H, W) = map(int, input().split())
	if H == 0:
		break
	tilis = [list(input()) for i in range(H)]
	answer = magicall(tilis, 0, 0)
	if type(answer) == tuple:
		print(answer[1], answer[0])
	else:
		print(answer)


while True:
	(h, w) = [int(x) for x in input().split()]
	if h == w == 0:
		break
	bool_ = [[0 for x in range(w)] for y in range(h)]
	tile = []
	for i in range(h):
		tile.append(list(input()))
	(x, y) = (0, 0)
	while True:
		if bool_[y][x]:
			print('LOOP')
			break
		else:
			bool_[y][x] = 1
			if tile[y][x] == '>':
				x += 1
			elif tile[y][x] == '<':
				x -= 1
			elif tile[y][x] == '^':
				y -= 1
			elif tile[y][x] == 'v':
				y += 1
			elif tile[y][x] == '.':
				print(x, y)
				break


for a in iter(input, '0 0'):
	m = [input() for _ in [0] * int(a.split()[0])]
	y = x = 0
	s = {(0, 0)}
	while 1:
		(u, v) = (x, y)
		c = m[y][x]
		if c == '>':
			x += 1
		if c == 'v':
			y += 1
		if c == '<':
			x -= 1
		if c == '^':
			y -= 1
		if c == '.':
			print(x, y)
			break
		if (x, y) in s:
			print('LOOP')
			break
		else:
			s |= {(x, y)}