The polar bears are going fishing. They plan to sail from (s_{x}, s_{y}) to (e_{x}, e_{y}). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).  If the wind blows to the east, the boat will move to (x + 1, y).  If the wind blows to the south, the boat will move to (x, y - 1).  If the wind blows to the west, the boat will move to (x - 1, y).  If the wind blows to the north, the boat will move to (x, y + 1). 

Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (x, y). Given the wind direction for t seconds, what is the earliest time they sail to (e_{x}, e_{y})?


-----Input-----

The first line contains five integers t, s_{x}, s_{y}, e_{x}, e_{y} (1 ≤ t ≤ 10^5,  - 10^9 ≤ s_{x}, s_{y}, e_{x}, e_{y} ≤ 10^9). The starting location and the ending location will be different.

The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).


-----Output-----

If they can reach (e_{x}, e_{y}) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).


-----Examples-----
Input
5 0 0 1 1
SESNW

Output
4

Input
10 5 3 3 6
NENSWESNEE

Output
-1



-----Note-----

In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.

In the second sample, they cannot sail to the destination.

Difficulty: EASY
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(n, x0, y0, x1, y1) = map(int, input().split())
if y0 > y1:
	a2 = 'S'
else:
	a2 = 'N'
if x0 > x1:
	a1 = 'W'
else:
	a1 = 'E'
(k1, k2) = (abs(x0 - x1), abs(y0 - y1))
s = input()
l = len(s)
i = 0
while i < l and (k2 > 0 or k1 > 0):
	if s[i] == a1:
		k1 -= 1
	elif s[i] == a2:
		k2 -= 1
	i += 1
if k1 > 0 or k2 > 0:
	print(-1)
else:
	print(i)


(n, sx, sy, dx, dy) = [int(i) for i in input().split()]
a = input()
count = 0
tag = 0
for i in a:
	if dx > sx and i == 'E':
		sx = sx + 1
	elif dx < sx and i == 'W':
		sx = sx - 1
	if dy > sy and i == 'N':
		sy = sy + 1
	if dy < sy and i == 'S':
		sy = sy - 1
	count += 1
	if dx == sx and dy == sy:
		print(count)
		tag = 1
		break
if tag == 0:
	print(-1)


d = {'E': (1, 0), 'S': (0, -1), 'W': (-1, 0), 'N': (0, 1)}
(t, sx, sy, ex, ey) = [int(x) for x in input().split()]
s = input()
for i in range(t):
	c = s[i]
	(dx, dy) = d[c]
	if abs(sx + dx - ex) <= abs(sx - ex) and abs(sy + dy - ey) <= abs(sy - ey):
		sx += dx
		sy += dy
	if sx == ex and sy == ey:
		print(i + 1)
		exit()
print(-1)


(n, x1, y1, x2, y2) = map(int, input().split())
s = input()
l = len(s)
p = x2 - x1
if p > 0:
	r = 'E'
else:
	r = 'W'
q = y2 - y1
if q > 0:
	t = 'N'
else:
	t = 'S'
f = False
g = False
c = 0
d = 0
for i in range(l):
	if s[i] == r:
		c += 1
	if s[i] == t:
		d += 1
	if c >= abs(p) and d >= abs(q):
		f = True
		break
if f == True:
	print(i + 1)
else:
	print(-1)


from sys import stdin
(t, sx, sy, ex, ey) = [int(i) for i in stdin.readline().split(' ')]
wind = stdin.readline().strip()
direction = {'E': 0, 'W': 0, 'N': 0, 'S': 0}
if ex >= sx:
	direction['E'] = ex - sx
else:
	direction['W'] = sx - ex
if ey >= sy:
	direction['N'] = ey - sy
else:
	direction['S'] = sy - ey
count = 0
flag = 0
for i in wind:
	if direction[i] > 0:
		direction[i] -= 1
	count += 1
	temp = direction['S'] + direction['N'] + direction['W'] + direction['E']
	if temp == 0:
		flag = 1
		print(count)
		break
if flag == 0:
	print('-1')


(t, sx, sy, ex, ey) = map(int, input().split())
a = input()
sl = None
el = None
scount = 0
ecount = 0
if sx > ex:
	sl = 'W'
	scount = sx - ex
elif sx < ex:
	sl = 'E'
	scount = ex - sx
else:
	sl = 'XX'
if sy > ey:
	el = 'S'
	ecount = sy - ey
elif sy < ey:
	el = 'N'
	ecount = ey - sy
else:
	el = 'YY'
if scount == 0 and ecount == 0:
	print(-1)
else:
	i = 0
	while i < t and (scount > 0 or ecount > 0):
		if scount == 0 and ecount == 0:
			break
		if a[i] == sl:
			scount -= 1
		if a[i] == el:
			ecount -= 1
		i += 1
	if scount > 0 or ecount > 0:
		print(-1)
	else:
		print(i)


(b, sx, sy, ex, ey) = map(int, input().split())
wind = input()
score = 0
for c in wind:
	if sx > ex and c == 'W':
		sx -= 1
	if sx < ex and c == 'E':
		sx += 1
	if sy > ey and c == 'S':
		sy -= 1
	if sy < ey and c == 'N':
		sy += 1
	score += 1
	if sx == ex and sy == ey:
		break
if sx == ex and sy == ey:
	print(score)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
w = input()
n = len(w)
w += ' '
ans = -1
i = 0
dx = ex - sx
dy = ey - sy
if abs(dx) + abs(dy) > t:
	pass
else:
	while i <= t and i < n:
		if dx == 0 and dy == 0:
			ans = i
			break
		if dx >= 0 and dy >= 0:
			if (w[i] != 'E' and w[i] != 'N' or (dx == 0 and w[i] == 'E') or (dy == 0 and w[i] == 'N')) and i < n:
				i += 1
			if dx > 0 and w[i] == 'E' and (i < n):
				i += 1
				dx -= 1
			if dy > 0 and w[i] == 'N' and (i < n):
				i += 1
				dy -= 1
		elif dx >= 0 and dy <= 0:
			if (w[i] != 'E' and w[i] != 'S' or (dx == 0 and w[i] == 'E') or (dy == 0 and w[i] == 'S')) and i < n:
				i += 1
			if dx > 0 and w[i] == 'E' and (i < n):
				i += 1
				dx -= 1
			if dy < 0 and w[i] == 'S' and (i < n):
				i += 1
				dy += 1
		elif dx <= 0 and dy >= 0:
			if (w[i] != 'W' and w[i] != 'N' or (dx == 0 and w[i] == 'W') or (dy == 0 and w[i] == 'N')) and i < n:
				i += 1
			if dx < 0 and w[i] == 'W' and (i < n):
				i += 1
				dx += 1
			if dy > 0 and w[i] == 'N' and (i < n):
				i += 1
				dy -= 1
		elif dx <= 0 and dy <= 0:
			if (w[i] != 'W' and w[i] != 'S' or (dx == 0 and w[i] == 'W') or (dy == 0 and w[i] == 'S')) and i < n:
				i += 1
			if dx < 0 and w[i] == 'W' and (i < n):
				i += 1
				dx += 1
			if dy < 0 and w[i] == 'S' and (i < n):
				i += 1
				dy += 1
if dx == 0 and dy == 0:
	ans = i
print(ans)


(t, sx, sy, ex, ey) = list(map(int, input().split()))
d = input()
c = 0
f = False
for i in range(t):
	if d[i] == 'N' and sy < ey:
		sy += 1
	elif d[i] == 'S' and sy > ey:
		sy -= 1
	elif d[i] == 'E' and sx < ex:
		sx += 1
	elif d[i] == 'W' and sx > ex:
		sx -= 1
	c += 1
	if sx == ex and sy == ey:
		f = True
		break
if not f:
	print(-1)
else:
	print(c)


(t, sx, sy, ex, ey) = map(int, input().split())
dirs = input()
(needx, needy) = (ex - sx, ey - sy)
neededString = ''
if needx == 0:
	if needy == 0:
		neededString = ''
	elif needy < 0:
		neededString += 'S' * abs(needy)
	else:
		neededString += 'N' * needy
elif needy == 0:
	if needx < 0:
		neededString += 'W' * abs(needx)
	else:
		neededString += 'E' * needx
else:
	if needx < 0:
		neededString += 'W' * abs(needx)
	else:
		neededString += 'E' * needx
	if needy < 0:
		neededString += 'S' * abs(needy)
	else:
		neededString += 'N' * needy
pos = 0
neededStringHash = {}
for _ in range(len(neededString)):
	if neededString[_] in neededStringHash.keys():
		neededStringHash[neededString[_]] += 1
	else:
		neededStringHash[neededString[_]] = 1
for _ in range(len(dirs)):
	if len(neededStringHash) == 0:
		break
	if dirs[_] in neededStringHash.keys():
		neededStringHash[dirs[_]] -= 1
		if neededStringHash.get(dirs[_]) == 0:
			del neededStringHash[dirs[_]]
		pos = _
if len(neededStringHash) == 0:
	print(pos + 1)
else:
	print(-1)


import math, sys
a = list(map(int, input().split()))
b = list(input())
if a[1] == a[3] and a[2] == a[4]:
	print(0)
	sys.exit(0)
flag = False
c = 0
for i in range(len(b)):
	c += 1
	if b[i] == 'S':
		if math.fabs(a[4] - (a[2] - 1)) > math.fabs(a[4] - a[2]):
			continue
		a[2] -= 1
	if b[i] == 'E':
		if math.fabs(a[3] - (a[1] + 1)) > math.fabs(a[3] - a[1]):
			continue
		a[1] += 1
	if b[i] == 'W':
		if math.fabs(a[3] - (a[1] - 1)) > math.fabs(a[3] - a[1]):
			continue
		a[1] -= 1
	if b[i] == 'N':
		if math.fabs(a[4] - (a[2] + 1)) > math.fabs(a[4] - a[2]):
			continue
		a[2] += 1
	if a[1] == a[3] and a[2] == a[4]:
		flag = True
		break
if flag:
	print(c)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
dic = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
for i in range(len(s)):
	dic[s[i]] += 1
passed = -1
if sx >= ex and dic['W'] >= sx - ex:
	if sy >= ey and dic['S'] >= sy - ey:
		passed = 0
	elif ey > sy and dic['N'] >= ey - sy:
		passed = 1
elif ex > sx and dic['E'] >= ex - sx:
	if sy >= ey and dic['S'] >= sy - ey:
		passed = 2
	elif ey > sy and dic['N'] >= ey - sy:
		passed = 3
dic = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
if passed == 0:
	for i in range(len(s)):
		dic[s[i]] += 1
		if dic['W'] >= sx - ex and dic['S'] >= sy - ey:
			print(i + 1)
			exit()
elif passed == 1:
	for i in range(len(s)):
		dic[s[i]] += 1
		if dic['W'] >= sx - ex and dic['N'] >= ey - sy:
			print(i + 1)
			exit()
elif passed == 2:
	for i in range(len(s)):
		dic[s[i]] += 1
		if dic['E'] >= ex - sx and dic['S'] >= sy - ey:
			print(i + 1)
			exit()
elif passed == 3:
	for i in range(len(s)):
		dic[s[i]] += 1
		if dic['E'] >= ex - sx and dic['N'] >= ey - sy:
			print(i + 1)
			exit()
else:
	print(-1)


(N, sx, sy, dx, dy) = tuple((int(i) for i in input().split()))
A = input()
answered = False
for i in range(len(A)):
	if A[i] == 'N' and sy < dy:
		sy += 1
	elif A[i] == 'S' and sy > dy:
		sy -= 1
	elif A[i] == 'E' and sx < dx:
		sx += 1
	elif A[i] == 'W' and sx > dx:
		sx -= 1
	if sx == dx and sy == dy:
		print(i + 1)
		answered = True
		break
if not answered:
	print('-1')


def main():
	ind = {'E': (1, 0), 'S': (0, -1), 'W': (-1, 0), 'N': (0, 1), '#': (0, 0)}
	(t, sx, sy, tx, ty) = list(map(int, input().split()))
	s = str(input())
	if sx == tx and sy == ty:
		print('0')
		return
	for i in range(0, t):
		if sx != tx and abs(sx + ind[s[i]][0] - tx) < abs(sx - tx):
			sx += ind[s[i]][0]
		if sy != ty and abs(sy + ind[s[i]][1] - ty) < abs(sy - ty):
			sy += ind[s[i]][1]
		if sx == tx and sy == ty:
			print(i + 1)
			return
	print('-1')

def __starting_point():
	main()
__starting_point()


(l, a, b, c, d) = map(int, input().split())
s = input()
t = 0
for i in s:
	if i == 'E' and a < c:
		a += 1
	elif i == 'W' and a > c:
		a -= 1
	elif i == 'S' and b > d:
		b -= 1
	elif i == 'N' and b < d:
		b += 1
	elif a == c and b == d:
		break
	t += 1
if a == c and b == d:
	print(t)
else:
	print(-1)


def sol():
	(t, ax, ay, bx, by) = list(map(int, input().split(' ')))
	wind = input()
	if bx - ax >= 0:
		chosex = 'E'
	else:
		chosex = 'W'
	if by - ay >= 0:
		chosey = 'N'
	else:
		chosey = 'S'
	x = 0
	y = 0
	i = 0
	while x != abs(bx - ax) or y != abs(by - ay):
		if i == t:
			i = -1
			break
		if wind[i] is chosex and x != abs(bx - ax):
			x += 1
		elif wind[i] is chosey and y != abs(by - ay):
			y += 1
		i += 1
	print(i)
sol()


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
f = 0
for i in range(t):
	if ex > sx:
		if s[i] == 'E':
			sx += 1
	if ex < sx:
		if s[i] == 'W':
			sx -= 1
	if ey > sy:
		if s[i] == 'N':
			sy += 1
	if ey < sy:
		if s[i] == 'S':
			sy -= 1
	if ex == sx and sy == ey:
		print(i + 1)
		f = -1
		break
if f == 0:
	print(-1)


(t, a, b, x, y) = map(int, input().split())
word = input().strip()
for (i, j) in zip(word, range(1, t + 1)):
	if i == 'N' and b < y:
		b += 1
	elif i == 'S' and b > y:
		b -= 1
	elif i == 'W' and a > x:
		a -= 1
	elif i == 'E' and a < x:
		a += 1
	if a == x and b == y:
		print(j)
		break
else:
	print(-1)


def solve():
	(n, sx, sy, ex, ey) = map(int, input().split())
	s = input()
	i = 0
	while i < n:
		if sx == ex and sy == ey:
			break
		else:
			if sx < ex and s[i] == 'E':
				sx += 1
			elif sx > ex and s[i] == 'W':
				sx -= 1
			if sy < ey and s[i] == 'N':
				sy += 1
			elif sy > ey and s[i] == 'S':
				sy -= 1
			i += 1
	if i == n and (not sx == ex or not sy == ey):
		print(-1)
		return
	else:
		print(i)
		return
try:
	solve()
except:
	pass


(t, x1, y1, x2, y2) = map(int, input().split())
l = input()
x = x2 - x1
y = y2 - y1
if x >= 0:
	a = 'E'
else:
	a = 'W'
if y >= 0:
	b = 'N'
else:
	b = 'S'
x = abs(x)
y = abs(y)
for i in range(t):
	if x == 0 and y == 0:
		print(i)
		break
	if l[i] == a:
		if x > 0:
			x -= 1
	if l[i] == b:
		if y > 0:
			y -= 1
	if i == t - 1:
		if x == 0 and y == 0:
			print(t)
		else:
			print(-1)


def get_index(l, x, n):
	l_count = l.count(x)
	result = None
	if n <= l_count:
		num = 0
		for item in enumerate(l):
			if item[1] == x:
				num += 1
			if num == n:
				result = item[0]
				break
	return result
(t, sx, sy, ex, ey) = map(int, input().split())
x = ex - sx
y = ey - sy
w = input()
a = w.count('E')
b = w.count('W')
c = w.count('N')
d = w.count('S')
if x > a or x < -b or y > c or (y < -d):
	print(-1)
elif x > 0:
	if y == 0:
		print(get_index(w, 'E', x) + 1)
	elif y > 0:
		print(max(get_index(w, 'E', x), get_index(w, 'N', y)) + 1)
	elif y < 0:
		print(max(get_index(w, 'E', x), get_index(w, 'S', -y)) + 1)
elif x < 0:
	if y == 0:
		print(get_index(w, 'W', -x) + 1)
	elif y > 0:
		print(max(get_index(w, 'W', -x), get_index(w, 'N', y)) + 1)
	elif y < 0:
		print(max(get_index(w, 'W', -x), get_index(w, 'S', -y)) + 1)
elif y > 0:
	print(get_index(w, 'N', y) + 1)
else:
	print(get_index(w, 'S', -y) + 1)


arr = list(map(int, input().split(' ')))
t = arr[0]
s = [arr[1], arr[2]]
d = [arr[3], arr[4]]
str = input()
y_mov = d[1] - s[1]
x_mov = d[0] - s[0]
directions = []
if x_mov < 0:
	directions.append('W')
elif x_mov > 0:
	directions.append('E')
elif x_mov == 0:
	directions.append(0)
if y_mov < 0:
	directions.append('S')
elif y_mov > 0:
	directions.append('N')
elif y_mov == 0:
	directions.append(0)
ct = [0, 0]
max_sec = 0
flag1 = 0
flag2 = 0
flag3 = 0
for i in range(len(str)):
	for j in range(len(directions)):
		if str[i] == directions[j]:
			ct[j] += 1
			max_sec = i + 1
		if ct[0] == abs(x_mov):
			flag1 = 1
		if ct[1] == abs(y_mov):
			flag2 = 1
		if flag1 == 1 and flag2 == 1:
			flag3 = 1
			break
	if flag3 == 1:
		break
if flag3 == 0:
	print(-1)
else:
	print(max_sec)


(t, sx, sy, ex, ey) = map(int, input().split(' '))
a = input()
x = ex - sx
y = ey - sy
time = 0
for i in a:
	time += 1
	if x > 0 and i == 'E':
		x -= 1
	if x < 0 and i == 'W':
		x += 1
	if y > 0 and i == 'N':
		y -= 1
	if y < 0 and i == 'S':
		y += 1
	if x == 0 and y == 0:
		break
if x == 0 and y == 0:
	print(time)
else:
	print(-1)


(t, sx, sy, ex, ey) = list(map(int, input().rstrip().split()))
s = input()
n1 = ex - sx
n2 = ey - sy
if n1 >= 0:
	c1 = 'E'
else:
	c1 = 'W'
if n2 >= 0:
	c2 = 'N'
else:
	c2 = 'S'
t = 0
n1 = abs(n1)
n2 = abs(n2)
for x in s:
	if n1 == 0 and n2 == 0:
		break
	if x == c1 and n1 > 0:
		n1 -= 1
	elif x == c2 and n2 > 0:
		n2 -= 1
	t += 1
if n1 == 0 and n2 == 0:
	print(t)
else:
	print(-1)


def main():
	(t, sx, sy, ex, ey) = list(map(int, input().split()))
	path = input()
	(dx, dy) = (ex - sx, ey - sy)
	if not dx and (not dy):
		print(0)
		return
	for (i, move) in enumerate(path):
		if dx < 0 and move == 'W':
			dx += 1
		elif dx > 0 and move == 'E':
			dx -= 1
		elif dy < 0 and move == 'S':
			dy += 1
		elif dy > 0 and move == 'N':
			dy -= 1
		if not dx and (not dy):
			print(i + 1)
			break
	else:
		print('-1')

def __starting_point():
	main()
__starting_point()


(t, sX, sY, eX, eY) = map(int, input().split())
d = {'E': (1, 0), 'S': (0, -1), 'W': (-1, 0), 'N': (0, 1)}
s = str(input())
if sX == eX and sY == eY:
	print('0')
	exit()
for i in range(0, t):
	if sX != eX and abs(sX + d[s[i]][0] - eX) < abs(sX - eX):
		sX += d[s[i]][0]
	if sY != eY and abs(sY + d[s[i]][1] - eY) < abs(sY - eY):
		sY += d[s[i]][1]
	if sX == eX and sY == eY:
		print(i + 1)
		exit()
print('-1')


(t, sx, sy, ex, ey) = map(int, input().split())
dire = input()
p = 0
for i in range(0, t):
	if dire[i] == 'S' and ey < sy:
		sy -= 1
	elif dire[i] == 'N' and ey > sy:
		sy += 1
	elif dire[i] == 'E' and ex > sx:
		sx += 1
	elif dire[i] == 'W' and ex < sx:
		sx -= 1
	if sx == ex and sy == ey:
		p = 1
		print(i + 1)
		break
if p == 0:
	print('-1')


(n, sx, sy, ex, ey) = map(int, input().split())
c = 0
d = input('')
for i in d:
	if sx < ex and i == 'E':
		sx += 1
	elif i == 'W' and sx > ex:
		sx -= 1
	elif sy < ey and i == 'N':
		sy += 1
	elif i == 'S' and sy > ey:
		sy -= 1
	elif sx == ex and sy == ey:
		break
	c += 1
if sx == ex and sy == ey:
	print(c)
else:
	print(-1)


INF = float('inf')

def calc(t, sx, sy, ex, ey, wind):
	if (sx, sy) == (ex, ey):
		return 0
	for i in range(len(wind)):
		wind_dir = wind[i]
		if wind_dir == 'E':
			(nsx, nsy) = (sx + 1, sy)
		elif wind_dir == 'S':
			(nsx, nsy) = (sx, sy - 1)
		elif wind_dir == 'W':
			(nsx, nsy) = (sx - 1, sy)
		elif wind_dir == 'N':
			(nsx, nsy) = (sx, sy + 1)
		if abs(ex - nsx) + abs(ey - nsy) > abs(ex - sx) + abs(ey - sy):
			continue
		(sx, sy) = (nsx, nsy)
		if (sx, sy) == (ex, ey):
			return i + 1
	return -1
(t, sx, sy, ex, ey) = map(int, input().split())
wind = input()
res = calc(t, sx, sy, ex, ey, wind)
print(res)


from collections import Counter
(t, sx, sy, ex, ey) = map(int, input().split())
directions = input()
dir_freq = dict(Counter(directions))
req_dir = {'N': 0, 'E': 0, 'W': 0, 'S': 0}
for i in req_dir:
	if i not in dir_freq:
		dir_freq[i] = 0
dx = ex - sx
dy = ey - sy
if dx > 0:
	req_dir['E'] += dx
if dx < 0:
	req_dir['W'] += abs(dx)
if dy > 0:
	req_dir['N'] += dy
if dy < 0:
	req_dir['S'] += abs(dy)
possible = True
for i in dir_freq:
	if dir_freq[i] < req_dir[i]:
		possible = False
		break
if not possible:
	print(-1)
else:
	i = 0
	while req_dir['N'] or req_dir['E'] or req_dir['W'] or req_dir['S']:
		if req_dir[directions[i]] > 0:
			req_dir[directions[i]] -= 1
		i += 1
	print(i)


def dist(first, second):
	return abs(second - first)
dic = {'E': lambda x, y: (x + 1, y), 'N': lambda x, y: (x, y + 1), 'S': lambda x, y: (x, y - 1), 'W': lambda x, y: (x - 1, y)}
(N, xs, ys, xe, ye) = map(int, input().split())
s = input()
for i in range(len(s)):
	(new_x, new_y) = dic[s[i]](xs, ys)
	if dist(new_x, xe) < dist(xs, xe) or dist(new_y, ye) < dist(ys, ye):
		(xs, ys) = (new_x, new_y)
	if xs == xe and ys == ye:
		print(i + 1)
		break
else:
	print(-1)


dir = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
(t, sx, sy, ex, ey) = map(int, input().split())
req = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
if sx > ex:
	req['W'] = sx - ex
if ex > sx:
	req['E'] = ex - sx
if sy > ey:
	req['S'] = sy - ey
if ey > sy:
	req['N'] = ey - sy
dirs = input()
left = lambda : req['N'] > 0 or req['S'] > 0 or req['W'] > 0 or (req['E'] > 0)
for i in range(t):
	if left():
		req[dirs[i]] -= 1
	else:
		print(i)
		break
else:
	print(-1 if left() else t)


from collections import Counter
line1 = list(map(int, input().split()))
directions = list(str(input()))
(t, s_x, s_y, e_x, e_y) = (line1[0], line1[1], line1[2], line1[3], line1[4])
dir_dict = {}
dirs = ['N', 'S', 'E', 'W']
(diff_x, diff_y) = (e_x - s_x, e_y - s_y)
keys = [0, 0]
timer = 0
for direction in dirs:
	dir_dict[direction] = directions.count(direction)
keys[0] = 'E' if diff_x > 0 else 'W'
keys[1] = 'N' if diff_y > 0 else 'S'
diff_x = abs(diff_x)
diff_y = abs(diff_y)
if diff_x > dir_dict[keys[0]] or diff_y > dir_dict[keys[1]]:
	print('-1')
elif diff_x == 0 and diff_y == 0:
	print(timer)
else:
	for wind in directions:
		timer += 1
		if wind == keys[0]:
			diff_x -= 1
		elif wind == keys[1]:
			diff_y -= 1
		if diff_x <= 0 and diff_y <= 0:
			print(timer)
			break


(t, sx, sy, ex, ey) = map(int, input().split())
(dx, dy) = (ex - sx, ey - sy)
wind = input()
fail = False
xcount = 0
ycount = 0
for i in wind:
	ycount += 1
	if dy > 0:
		if i == 'N':
			dy -= 1
	if dy < 0:
		if i == 'S':
			dy += 1
	if dy == 0:
		break
else:
	fail = True
for i in wind:
	xcount += 1
	if dx > 0:
		if i == 'E':
			dx -= 1
	if dx < 0:
		if i == 'W':
			dx += 1
	if dx == 0:
		break
else:
	fail = True
if fail == True:
	print(-1)
else:
	print(max(xcount, ycount))


(t, x1, y1, x2, y2) = map(int, input().split(' '))
dire = input()
if x1 <= x2:
	dirx = 'E'
else:
	dirx = 'W'
adirx = abs(x1 - x2)
if y1 <= y2:
	diry = 'N'
else:
	diry = 'S'
adiry = abs(y1 - y2)
cnt = 0
flag = 0
for d in dire:
	if adirx == 0 and adiry == 0:
		print(cnt)
		flag = 1
		break
	cnt += 1
	if d == dirx and adirx > 0:
		adirx -= 1
	if d == diry and adiry > 0:
		adiry -= 1
if adirx != 0 or adiry != 0:
	print(-1)
elif adirx == 0 and adiry == 0 and (flag == 0):
	print(cnt)


(t, sx, sy, ex, ey) = map(int, input().split())
L = list(input())
time = 0
for i in L:
	if i == 'W' and sx > ex:
		sx -= 1
	elif i == 'E' and sx < ex:
		sx += 1
	elif i == 'N' and sy < ey:
		sy += 1
	elif i == 'S' and sy > ey:
		sy -= 1
	time += 1
	if sy == ey and sx == ex:
		break
if time <= t and (sy == ey and sx == ex):
	print(time)
else:
	print('-1')


(t, sx, sy, ex, ey) = map(int, input().split())
winds = list(input())

def dist(x, y):
	return abs(x - ex) + abs(y - ey)
for zzz in range(t):
	(new_x, new_y) = (sx, sy)
	if winds[zzz] == 'N':
		new_y += 1
	if winds[zzz] == 'S':
		new_y -= 1
	if winds[zzz] == 'E':
		new_x += 1
	if winds[zzz] == 'W':
		new_x -= 1
	if dist(new_x, new_y) < dist(sx, sy):
		sx = new_x
		sy = new_y
	if sx == ex and sy == ey:
		if zzz + 1 <= t:
			print(zzz + 1)
			break
else:
	print(-1)


i = 0
(t, sx, sy, ex, ey) = list(map(int, input().split()))
second_string = input()
while sy != ey or sx != ex:
	if i == t:
		break
	if second_string[i] == 'E':
		if sx < ex:
			sx += 1
	elif second_string[i] == 'W':
		if sx > ex:
			sx -= 1
	elif second_string[i] == 'N':
		if sy < ey:
			sy += 1
	elif second_string[i] == 'S':
		if sy > ey:
			sy -= 1
	i += 1
if (sy == ey and sx == ex) is False:
	print(-1)
else:
	print(i)


(t, sx, sy, ex, ey) = map(int, input().split())
d = {'W': max(0, sx - ex), 'E': max(0, ex - sx), 'N': max(0, ey - sy), 'S': max(0, sy - ey)}
for (i, c) in enumerate(input(), 1):
	if d[c] > 0:
		d[c] -= 1
	if any(d.values()) == False:
		print(i)
		break
else:
	print(-1)


def check(dif_x, dif_y):
	if dif_x > 0:
		x = 'E'
	elif dif_x < 0:
		x = 'W'
	else:
		x = ''
	if dif_y > 0:
		y = 'N'
	elif dif_y < 0:
		y = 'S'
	else:
		y = ''
	return (x, y)
(t, x1, y1, x2, y2) = input().split()
s = input()
(x1, x2) = (int(x1), int(x2))
(y1, y2) = (int(y1), int(y2))
dif_x = x2 - x1
dif_y = y2 - y1
(x, y) = check(dif_x, dif_y)
x_count = 0
y_count = 0
count = 0
b = False
for i in s:
	if i == x:
		x_count += 1
	elif i == y:
		y_count += 1
	count += 1
	if x_count >= abs(dif_x) and y_count >= abs(dif_y):
		b = True
		break
if b:
	print(count)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
di = input()
cnt = 0
f = 0
for item in di:
	if item == 'N':
		temp = sy + 1
		if abs(ey - temp) < abs(ey - sy):
			sy += 1
	elif item == 'S':
		temp = sy - 1
		if abs(ey - temp) < abs(ey - sy):
			sy -= 1
	elif item == 'E':
		temp = sx + 1
		if abs(ex - temp) < abs(ex - sx):
			sx += 1
	else:
		temp = sx - 1
		if abs(ex - temp) < abs(ex - sx):
			sx -= 1
	cnt += 1
	if sx == ex and sy == ey:
		f = 1
		break
print(cnt if f else -1)


(t, sx, sy, ex, ey) = [int(i) for i in input().split()]
s = input()
X = ex - sx
Y = ey - sy
res = -1
for i in range(t):
	if X > 0 and s[i] == 'E':
		X -= 1
	elif X < 0 and s[i] == 'W':
		X += 1
	if Y > 0 and s[i] == 'N':
		Y -= 1
	elif Y < 0 and s[i] == 'S':
		Y += 1
	if X == 0 and Y == 0:
		res = i + 1
		break
print(res)


(t, sx, sy, ex, ey) = map(int, input().split())
q = 'N' if ey > sy else 'S'
w = 'E' if ex > sx else 'W'
ex = abs(ex - sx)
ey = abs(ey - sy)
s = input()
for i in range(t):
	if ey != 0 and s[i] == q:
		ey -= 1
	if ex != 0 and s[i] == w:
		ex -= 1
	if ex == 0 and ey == 0:
		break
print(i + 1 if ex == 0 and ey == 0 else -1)


(t, sx, sy, ex, ey) = (int(i) for i in input().split())
directions = list(input())
lateral = ex - sx
transverse = ey - sy
time = 0
for d in directions:
	if not (lateral or transverse):
		break
	if d == 'S':
		if transverse < 0:
			transverse += 1
	elif d == 'N':
		if transverse > 0:
			transverse -= 1
	elif d == 'E':
		if lateral > 0:
			lateral -= 1
	elif d == 'W':
		if lateral < 0:
			lateral += 1
	time += 1
if not (lateral or transverse):
	print(time)
else:
	print(-1)


def main():
	(t, sx, sy, ex, ey) = map(int, input().split())
	dirs = input()
	x_dist = ex - sx
	x_dir = 'E' if x_dist >= 0 else 'W'
	x_dist = x_dist if x_dist >= 0 else -x_dist
	y_dist = ey - sy
	y_dir = 'N' if y_dist >= 0 else 'S'
	y_dist = y_dist if y_dist >= 0 else -y_dist
	for i in range(t):
		if dirs[i] == x_dir and x_dist > 0:
			x_dist -= 1
		elif dirs[i] == y_dir and y_dist > 0:
			y_dist -= 1
		if y_dist == 0 and x_dist == 0:
			return i + 1
	return -1
print(main())


(n, x, y, xx, yy) = map(int, input().split())
s = input()
c = 0
if x == xx and y == yy:
	print(0)
else:
	for i in range(n):
		c = c + 1
		if s[i] == 'N':
			if yy > y:
				y = y + 1
		elif s[i] == 'S':
			if yy < y:
				y -= 1
		elif s[i] == 'E':
			if xx > x:
				x += 1
		elif s[i] == 'W':
			if xx < x:
				x -= 1
		if x == xx and y == yy:
			print(c)
			break
	else:
		print(-1)


(n, x, y, a, b) = map(int, input().split())
str = input()
n = len(str)
dify = b - y
difx = a - x
seconds = 0
if dify < 0:
	for i in range(n):
		if str[i] == 'S' and dify != 0:
			dify += 1
			seconds = max(seconds, i)
else:
	for i in range(n):
		if str[i] == 'N' and dify != 0:
			dify -= 1
			seconds = max(seconds, i)
if difx < 0:
	for i in range(n):
		if str[i] == 'W' and difx != 0:
			difx += 1
			seconds = max(seconds, i)
else:
	for i in range(n):
		if str[i] == 'E' and difx != 0:
			difx -= 1
			seconds = max(seconds, i)
if difx == 0 and dify == 0:
	print(seconds + 1)
else:
	print(-1)


X = list(map(int, input().split()))
(XTotal, YTotal) = (X[-2] - X[1], X[-1] - X[2])
(S, Cnt) = (input(), 0)
for i in S:
	if XTotal == 0 and YTotal == 0:
		print(Cnt)
		exit()
	if i in 'EW':
		if XTotal > 0 and i == 'E':
			XTotal -= 1
		if XTotal < 0 and i == 'W':
			XTotal += 1
	else:
		if YTotal > 0 and i == 'N':
			YTotal -= 1
		if YTotal < 0 and i == 'S':
			YTotal += 1
	Cnt += 1
	if XTotal == 0 and YTotal == 0:
		print(Cnt)
		exit()
print(-1)


l = list(map(int, input().split()))
s = input()
c = 0
n = l[0]
sx = l[1]
sy = l[2]
ex = l[3]
ey = l[4]
dx = abs(ex - sx)
dy = abs(ey - sy)
i = 0
while i < n:
	if s[i] == 'E':
		temp = abs(ex - (sx + 1))
		if sx != ex and temp < dx:
			dx = temp
			sx += 1
	elif s[i] == 'S':
		temp = abs(ey - (sy - 1))
		if sy != ey and temp < dy:
			dy = temp
			sy -= 1
	elif s[i] == 'N':
		temp = abs(ey - (sy + 1))
		if sy != ey and temp < dy:
			dy = temp
			sy += 1
	elif s[i] == 'W':
		temp = abs(ex - (sx - 1))
		if sx != sy and temp < dx:
			dx = temp
			sx -= 1
	c += 1
	if sy == ey and sx == ex:
		print(c)
		break
	i += 1
else:
	print(-1)


(t, s1, s2, e1, e2) = map(int, input().split())
x = input()
a = e1 - s1
b = e2 - s2
if a < 0:
	a = -a
	A = 'W'
else:
	A = 'E'
if b < 0:
	b = -b
	B = 'S'
else:
	B = 'N'
c = 0
for i in x:
	c += 1
	if i == A:
		a -= 1
	if i == B:
		b -= 1
	if a <= 0 and b <= 0:
		break
if a <= 0 and b <= 0:
	print(c)
else:
	print(-1)


(n, sx, sy, ex, ey) = map(int, input().split(' '))
reqx = ex - sx
reqy = ey - sy
str = input()
for i in range(n):
	if reqx < 0:
		if str[i] == 'W':
			reqx += 1
	if reqy < 0:
		if str[i] == 'S':
			reqy += 1
	if reqx > 0:
		if str[i] == 'E':
			reqx -= 1
	if reqy > 0:
		if str[i] == 'N':
			reqy -= 1
	if reqx == reqy and reqx == 0:
		print(i + 1)
		return
print(-1)


(t, ix, iy, fx, fy) = map(int, input().split())
s = input()
d = {'x': fx - ix, 'y': fy - iy}
f = 1
if d['x'] < 0:
	if s.count('W') < abs(d['x']):
		f = 0
elif s.count('E') < abs(d['x']):
	f = 0
if d['y'] < 0:
	if s.count('S') < abs(d['y']):
		f = 0
elif s.count('N') < abs(d['y']):
	f = 0
if not f:
	print(-1)
	exit()
c = 0
for i in range(t):
	if s[i] == 'N':
		if d['y'] > 0:
			c = max(c, i + 1)
			d['y'] -= 1
	elif s[i] == 'S':
		if d['y'] < 0:
			c = max(c, i + 1)
			d['y'] += 1
	elif s[i] == 'E':
		if d['x'] > 0:
			c = max(c, i + 1)
			d['x'] -= 1
	elif d['x'] < 0:
		c = max(c, i + 1)
		d['x'] += 1
	if abs(d['x']) + abs(d['y']) == 0:
		break
print(c)


from sys import stdin, exit
(t, sx, sy, ex, ey) = map(int, stdin.readline().split())
a = ex - sx
b = ey - sy
(n, s, e, w) = (0, 0, 0, 0)
if a < 0:
	w = a
else:
	e = a
if b < 0:
	s = b
else:
	n = b
r = stdin.readline().rstrip()
c = 0
for i in range(t):
	if r[i] == 'W' and w != 0:
		w += 1
		c += 1
	elif r[i] == 'E' and e != 0:
		e -= 1
		c += 1
	elif r[i] == 'S' and s != 0:
		s += 1
		c += 1
	elif r[i] == 'N' and n != 0:
		n -= 1
		c += 1
	else:
		if n == 0 and s == 0 and (w == 0) and (e == 0):
			break
		c += 1
	if i == t - 1 and (n != 0 or s != 0 or e != 0 or (w != 0)):
		print(-1)
		exit()
print(c)


(t, x, y, xe, ye) = map(int, input().split())
directions = input()
(i, j) = (x, y)
t = 0
for direction in directions:
	if i == xe and j == ye:
		print(t)
		exit()
	if direction == 'E' and xe > i:
		i += 1
	elif direction == 'S' and ye < j:
		j -= 1
	elif direction == 'N' and ye > j:
		j += 1
	elif direction == 'W' and xe < i:
		i -= 1
	t += 1
if i == xe and j == ye:
	print(t)
	exit()
print(-1)


(m, a, ay, b, by) = map(int, input().split())
s = input() + '0'
x = 'W' if a > b else 'E'
y = 'S' if ay > by else 'N'
(c, d) = (abs(a - b), abs(ay - by))
for i in range(m):
	if s[i] == x and c > 0:
		c -= 1
	if s[i] == y and d > 0:
		d -= 1
	if c == d == 0:
		print(i + 1)
		break
else:
	print(-1)


(n, x1, y1, x2, y2) = map(int, input().split())
s = input()
pMoves = {'E': 0, 'W': 0, 'N': 0, 'S': 0}
f = 0
size = 0
for wind in s:
	size += 1
	pMoves[wind] += 1
	(x, y) = (x2 - x1, y2 - y1)
	pos = [False, False]
	if y < 0:
		pos[0] = pMoves['S'] >= abs(y)
		if x < 0:
			pos[1] = pMoves['W'] >= abs(x)
		else:
			pos[1] = pMoves['E'] >= x
	else:
		pos[0] = pMoves['N'] >= y
		if x < 0:
			pos[1] = pMoves['W'] >= abs(x)
		else:
			pos[1] = pMoves['E'] >= x
	if pos[1] and pos[0]:
		f = 1
		print(size)
		break
if not f:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
direct = input()
x = y = 0
rx = ex - sx
ry = ey - sy
check = 0
for i in range(t):
	if rx >= 0 and ry >= 0:
		if direct[i] == 'N':
			if y < ry:
				y += 1
		elif direct[i] == 'E':
			if x < rx:
				x += 1
		if x == rx and y == ry:
			check = 1
			index = i
			break
	elif rx >= 0 and ry < 0:
		if direct[i] == 'S':
			if y < -ry:
				y += 1
		elif direct[i] == 'E':
			if x < rx:
				x += 1
		if x == rx and y == -ry:
			check = 1
			index = i
			break
	elif rx < 0 and ry >= 0:
		if direct[i] == 'N':
			if y < ry:
				y += 1
		elif direct[i] == 'W':
			if x < -rx:
				x += 1
		if x == -rx and y == ry:
			check = 1
			index = i
			break
	else:
		if direct[i] == 'S':
			if y < -ry:
				y += 1
		elif direct[i] == 'W':
			if x < -rx:
				x += 1
		if x == -rx and y == -ry:
			check = 1
			index = i
			break
if check:
	print(index + 1)
else:
	print(-1)


(n, sx, sy, ex, ey) = map(int, input().strip().split(' '))
if ex - sx >= 0:
	d1 = 'E'
	dd1 = ex - sx
else:
	d1 = 'W'
	dd1 = abs(ex - sx)
if ey - sy >= 0:
	d2 = 'N'
	dd2 = ey - sy
else:
	d2 = 'S'
	dd2 = abs(ey - sy)
s = input()
i = 0
while i < n:
	if s[i] == d2:
		dd2 -= 1
	if s[i] == d1:
		dd1 -= 1
	if dd1 <= 0 and dd2 <= 0:
		break
	i += 1
print(i + 1) if i != n else print(-1)


(n, x0, y0, x1, y1) = map(int, input().split())
s = input()
if y0 > y1:
	a2 = 'S'
else:
	a2 = 'N'
if x0 > x1:
	a1 = 'W'
else:
	a1 = 'E'
(ch, cv) = (abs(x0 - x1), abs(y0 - y1))
i = 0
while i < n and (ch > 0 or cv > 0):
	if s[i] == a1:
		ch -= 1
	elif s[i] == a2:
		cv -= 1
	i += 1
if cv > 0 or ch > 0:
	print(-1)
else:
	print(i)


(t, x, y, u, v) = map(int, input().split())
dx = u - x
dy = v - y
p = input()
(e, s, w, n) = (p.count('E'), p.count('S'), p.count('W'), p.count('N'))
if -w > dx or e < dx or -s > dy or (n < dy):
	print(-1)
else:
	for i in range(len(p)):
		if p[i] == 'E':
			if dx > 0:
				dx -= 1
		elif p[i] == 'S':
			if dy < 0:
				dy += 1
		elif p[i] == 'W':
			if dx < 0:
				dx += 1
		elif dy > 0:
			dy -= 1
		if dx == 0 and dy == 0:
			print(i + 1)
			break


def solve():
	(t, sx, sy, ex, ey) = map(int, input().split())
	order = input()

	def dist(x1, y1):
		return abs(x1 - ex) + abs(y1 - ey)
	for (i, d) in enumerate(order):
		if d == 'N':
			if dist(sx, sy + 1) < dist(sx, sy):
				sy += 1
		elif d == 'E':
			if dist(sx + 1, sy) < dist(sx, sy):
				sx += 1
		elif d == 'S':
			if dist(sx, sy - 1) < dist(sx, sy):
				sy -= 1
		elif dist(sx - 1, sy) < dist(sx, sy):
			sx -= 1
		if sx == ex and sy == ey:
			return i + 1
	return -1
print(solve())


(t, sx, sy, ex, ey) = map(int, input().split())
st = input()
if sx < ex:
	e = ex - sx
	if sy < ey:
		n = ey - sy
		ind = 0
		while ind < t:
			if e <= 0 and n <= 0:
				break
			if st[ind] == 'E':
				e -= 1
			if st[ind] == 'N':
				n -= 1
			ind += 1
		if e <= 0 and n <= 0:
			print(ind)
		else:
			print(-1)
	elif sy > ey:
		s = sy - ey
		ind = 0
		while ind < t:
			if e <= 0 and s <= 0:
				break
			if st[ind] == 'E':
				e -= 1
			if st[ind] == 'S':
				s -= 1
			ind += 1
		if e <= 0 and s <= 0:
			print(ind)
		else:
			print(-1)
	else:
		ind = 0
		while ind < t:
			if e <= 0:
				break
			if st[ind] == 'E':
				e -= 1
			ind += 1
		if e <= 0:
			print(ind)
		else:
			print(-1)
elif sx > ex:
	w = sx - ex
	if sy < ey:
		n = ey - sy
		ind = 0
		while ind < t:
			if w <= 0 and n <= 0:
				break
			if st[ind] == 'W':
				w -= 1
			if st[ind] == 'N':
				n -= 1
			ind += 1
		if w <= 0 and n <= 0:
			print(ind)
		else:
			print(-1)
	elif sy > ey:
		s = sy - ey
		ind = 0
		while ind < t:
			if w <= 0 and s <= 0:
				break
			if st[ind] == 'W':
				w -= 1
			if st[ind] == 'S':
				s -= 1
			ind += 1
		if w <= 0 and s <= 0:
			print(ind)
		else:
			print(-1)
	else:
		ind = 0
		while ind < t:
			if w <= 0:
				break
			if st[ind] == 'W':
				w -= 1
			ind += 1
		if w <= 0:
			print(ind)
		else:
			print(-1)
elif sy < ey:
	n = ey - sy
	ind = 0
	while ind < t:
		if n <= 0:
			break
		if st[ind] == 'N':
			n -= 1
		ind += 1
	if n <= 0:
		print(ind)
	else:
		print(-1)
else:
	s = sy - ey
	ind = 0
	while ind < t:
		if s <= 0:
			break
		if st[ind] == 'S':
			s -= 1
		ind += 1
	if s <= 0:
		print(ind)
	else:
		print(-1)


import math
(t, x_i, y_i, x_f, y_f) = input().split(' ')
command = input()
t = int(t)
x_i = int(x_i)
y_i = int(y_i)
x_f = int(x_f)
y_f = int(y_f)
v = y_f - y_i
h = x_f - x_i
coor = int(0)
if v > 0:
	for i in range(0, len(command)):
		if command[i] == 'N' and v > 0:
			v -= 1
			coor = max(i, coor)
	if h > 0:
		for i in range(0, len(command)):
			if command[i] == 'E' and h > 0:
				h -= 1
				coor = max(i, coor)
	elif h < 0:
		for i in range(0, len(command)):
			if command[i] == 'W' and h < 0:
				h += 1
				coor = max(i, coor)
	if h == 0 and v == 0:
		print(coor + 1)
	else:
		print('-1')
else:
	for i in range(0, len(command)):
		if command[i] == 'S' and v < 0:
			v += 1
			coor = max(i, coor)
	if h > 0:
		for i in range(0, len(command)):
			if command[i] == 'E' and h > 0:
				h -= 1
				coor = max(i, coor)
	elif h < 0:
		for i in range(0, len(command)):
			if command[i] == 'W' and h < 0:
				h += 1
				coor = max(i, coor)
	if h == 0 and v == 0:
		print(coor + 1)
	else:
		print('-1')


(t, sx, sy, ex, ey) = map(int, input().split(' '))
dirs = list(input())
dx = ex - sx
dy = ey - sy
lx = 'E'
if dx < 0:
	lx = 'W'
ly = 'N'
if dy < 0:
	ly = 'S'
dx = abs(dx)
dy = abs(dy)
t = 0
while dx > 0 or dy > 0:
	if dirs[t] == lx:
		dx -= 1
	if dirs[t] == ly:
		dy -= 1
	t += 1
	if t >= len(dirs):
		break
if dx <= 0 and dy <= 0:
	print(t)
else:
	print(-1)


def inp(n):
	if n == 1:
		return map(int, stdin.readline().split())
	elif n == 2:
		return map(float, stdin.readline().split())
	else:
		return map(str, stdin.readline().split())
from sys import stdin
(t, x1, y1, x2, y2) = inp(1)
s = input()
for (i, j) in enumerate(s):
	if j == 'N':
		if y1 < y2:
			y1 += 1
	elif j == 'S':
		if y1 > y2:
			y1 -= 1
	elif j == 'E':
		if x2 > x1:
			x1 += 1
	elif j == 'W':
		if x2 < x1:
			x1 -= 1
	if x1 == x2 and y1 == y2:
		exit(print(i + 1))
print(-1)


l1 = [int(i) for i in input().split()]
s = [l1[1], l1[2]]
e = [l1[3], l1[4]]
wind = [c for c in input()]
beloved = ['W', 'N']

def sub(num1, num2):
	return num1 - num2

def add(num1, num2):
	return num1 + num2
op = [sub, add]
if s[0] < e[0]:
	beloved[0] = 'E'
	op[0] = add
if s[1] > e[1]:
	beloved[1] = 'S'
	op[1] = sub
time = 0
for w in wind:
	if s[0] == e[0] and s[1] == e[1]:
		print(time)
		exit()
	time += 1
	for i in (0, 1):
		if s[i] == e[i]:
			continue
		if w == beloved[i]:
			s[i] = op[i](s[i], 1)
if s[0] == e[0] and s[1] == e[1]:
	print(time)
	exit()
print(-1)


(t, s_x, s_y, e_x, e_y) = [int(x) for x in input().strip().split()]
s = (s_x, s_y)
e = (e_x, e_y)
directions = list(input().strip())
d = {'E': (1, 0), 'S': (0, -1), 'W': (-1, 0), 'N': (0, 1)}

def anchor(s, e, direction, d=d):
	val = d[direction]
	s_temp = (s[0] + val[0], s[1] + val[1])
	org_dis = abs(s[0] - e[0]) + abs(s[1] - e[1])
	mod_dis = abs(s_temp[0] - e[0]) + abs(s_temp[1] - e[1])
	if mod_dis > org_dis:
		return s
	return s_temp
count = 0
flag = False
for i in directions:
	s = anchor(s, e, i)
	count += 1
	if s[0] == e[0] and s[1] == e[1]:
		flag = True
		break
if flag:
	print(count)
else:
	print(-1)


def sail():
	s = [int(x) for x in input().split()]
	(t, sx, sy, ex, ey) = (s[0], s[1], s[2], s[3], s[4])
	wind = list(input())
	xd = ex - sx
	yd = ey - sy
	cdx = ''
	cdy = ''
	if xd < 0:
		if wind.count('W') < abs(xd):
			print(-1)
			return
		xd = abs(xd)
		cdx = 'W'
	elif xd > 0:
		if wind.count('E') < xd:
			print(-1)
			return
		cdx = 'E'
	if yd < 0:
		if wind.count('S') < abs(yd):
			print(-1)
			return
		yd = abs(yd)
		cdy = 'S'
	elif yd > 0:
		if wind.count('N') < yd:
			print(-1)
			return
		cdy = 'N'
	t = 0
	i = 0
	while i < len(wind):
		if xd == 0 and yd == 0:
			print(t)
			return
		if wind[i] == cdx and xd > 0:
			xd = xd - 1
		elif wind[i] == cdy and yd > 0:
			yd = yd - 1
		t = t + 1
		i = i + 1
	if (xd, yd) == (0, 0):
		print(t)
		return
sail()


import sys
(t, sx, sy, ex, ey) = [int(x) for x in input().split(' ')]
s = input()
if sx == ex and sy == ey:
	print(0)
	sys.exit()
for i in range(t):
	if s[i] == 'N' and abs(ey - (sy + 1)) < abs(ey - sy):
		sy += 1
	if s[i] == 'S' and abs(ey - (sy - 1)) < abs(ey - sy):
		sy -= 1
	if s[i] == 'E' and abs(ex - (sx + 1)) < abs(ex - sx):
		sx += 1
	if s[i] == 'W' and abs(ex - (sx - 1)) < abs(ex - sx):
		sx -= 1
	if sx == ex and sy == ey:
		print(i + 1)
		break
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
c = 0
y = ey - sy
x = ex - sx
s = input()
i = 0
while y | x != 0 and i < t:
	if y > 0 and s[i] == 'N':
		y -= 1
	elif y < 0 and s[i] == 'S':
		y += 1
	if x > 0 and s[i] == 'E':
		x -= 1
	elif x < 0 and s[i] == 'W':
		x += 1
	i += 1
if y | x == 0:
	print(i)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
x = 0
y = 0
if sx >= ex and sy >= ey:
	tot1 = sx - ex
	tot2 = sy - ey
	for i in range(len(s)):
		if s[i] == 'W':
			if tot1 > x:
				x += 1
		if s[i] == 'S':
			if tot2 > y:
				y += 1
		if x == tot1 and y == tot2:
			print(i + 1)
			exit()
elif sx <= ex and sy <= ey:
	tot1 = ex - sx
	tot2 = ey - sy
	for i in range(len(s)):
		if s[i] == 'E':
			if tot1 > x:
				x += 1
		if s[i] == 'N':
			if tot2 > y:
				y += 1
		if x == tot1 and y == tot2:
			print(i + 1)
			exit()
elif sx >= ex and sy <= ey:
	tot1 = sx - ex
	tot2 = ey - sy
	for i in range(len(s)):
		if s[i] == 'W':
			if tot1 > x:
				x += 1
		if s[i] == 'N':
			if tot2 > y:
				y += 1
		if x == tot1 and y == tot2:
			print(i + 1)
			exit()
elif sx <= ex and sy >= ey:
	tot1 = ex - sx
	tot2 = sy - ey
	for i in range(len(s)):
		if s[i] == 'E':
			if tot1 > x:
				x += 1
		if s[i] == 'S':
			if tot2 > y:
				y += 1
		if x == tot1 and y == tot2:
			print(i + 1)
			exit()
print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
if ex > sx:
	xch = 'E'
else:
	xch = 'W'
if ey > sy:
	ych = 'N'
else:
	ych = 'S'
x = abs(ex - sx)
y = abs(ey - sy)
xp = -1
xc = 0
while xc < x:
	xp = s.find(xch, xp + 1)
	if xp == -1:
		break
	xc += 1
yp = -1
yc = 0
while yc < y:
	yp = s.find(ych, yp + 1)
	if yp == -1:
		break
	yc += 1
if yp == -1 and y > 0 or (xp == -1 and x > 0):
	print(-1)
else:
	print(max(xp, yp) + 1)


(t, sx, sy, ex, ey) = [int(x) for x in input().split()]
dir = input()
allow = []
if ex - sx > 0:
	allow.append('E')
elif ex - sx < 0:
	allow.append('W')
if ey - sy > 0:
	allow.append('N')
elif ey - sy < 0:
	allow.append('S')
curr = [sx, sy]
end = [ex, ey]
mov = {'E': (1, 0), 'W': (-1, 0), 'N': (0, 1), 'S': (0, -1)}
ans = 0
for (t, d) in enumerate(dir):
	ans += 1
	if d in allow:
		if curr[0] != end[0]:
			curr[0] += mov[d][0]
		if curr[1] != end[1]:
			curr[1] += mov[d][1]
	if curr == end:
		break
if curr == end:
	print(ans)
else:
	print(-1)


import sys, os, io, time, copy
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
import math

def main():
	(t, s1, s2, e1, e2) = map(int, input().split())
	string = input()
	x_shift = e1 - s1
	y_shift = e2 - s2
	east = 0
	west = 0
	north = 0
	south = 0
	if x_shift >= 0:
		east = x_shift
	else:
		west = abs(x_shift)
	if y_shift >= 0:
		north = y_shift
	else:
		south = abs(y_shift)
	ea = we = no = so = 0
	flag = 0
	req = 0
	if no == north:
		no = -1
	if ea == east:
		ea = -1
	if so == south:
		so = -1
	if we == west:
		we = -1
	for i in range(len(string)):
		s = string[i]
		if s == 'N' and no >= 0:
			no += 1
		elif s == 'S' and so >= 0:
			so += 1
		elif s == 'E' and ea >= 0:
			ea += 1
		elif s == 'W' and we >= 0:
			we += 1
		if no == north:
			no = -1
		if ea == east:
			ea = -1
		if so == south:
			so = -1
		if we == west:
			we = -1
		if ea == we == so == no == -1:
			flag = 1
			req = i + 1
			break
	if flag == 1:
		print(req)
	else:
		print(-1)
main()


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
(vert, hori) = ('', '')
if ey > sy:
	vert = 'N'
else:
	vert = 'S'
if ex > sx:
	hori = 'E'
else:
	hori = 'W'
(x, y) = (abs(ex - sx), abs(ey - sy))
cnt = 0
for i in range(0, len(s)):
	if s[i] == vert:
		y -= 1
	if s[i] == hori:
		x -= 1
	if x <= 0 and y <= 0:
		print(i + 1)
		break
else:
	print(-1)


(a, x, y, d, e) = map(int, input().split())
k = input()
m = 0
for i in k:
	m += 1
	if i == 'S' and y > e:
		y -= 1
	elif i == 'E' and x < d:
		x += 1
	elif i == 'N' and y < e:
		y += 1
	elif i == 'W' and x > d:
		x -= 1
	if y == e and x == d:
		print(m)
		break
if y != e or x != d:
	print(-1)


x = list(map(int, input().split()))
z = input()
c = 0
t = False
if x[1] == x[3] and x[2] == x[4]:
	print(0)
	exit()
if x[1] < x[3] and x[2] < x[4]:
	for i in z:
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
		if i == 'E' and x[1] != x[3]:
			x[1] += 1
		elif i == 'N' and x[2] != x[4]:
			x[2] += 1
		c += 1
elif x[1] > x[3] and x[2] > x[4]:
	for i in z:
		if i == 'W' and x[1] != x[3]:
			x[1] -= 1
		elif i == 'S' and x[4] != x[2]:
			x[2] -= 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
elif x[1] > x[3] and x[2] < x[4]:
	for i in z:
		if i == 'W' and x[1] != x[3]:
			x[1] -= 1
		elif i == 'N' and x[2] != x[4]:
			x[2] += 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
elif x[1] < x[3] and x[2] > x[4]:
	for i in z:
		if i == 'E' and x[3] != x[1]:
			x[1] += 1
		elif i == 'S' and x[4] != x[2]:
			x[2] -= 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
elif x[1] == x[3] and x[2] < x[4]:
	for i in z:
		if i == 'N' and x[4] != x[2]:
			x[2] += 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
elif x[1] == x[3] and x[2] > x[4]:
	for i in z:
		if i == 'S' and x[4] != x[2]:
			x[2] -= 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
elif x[1] < x[3] and x[2] == x[4]:
	for i in z:
		if i == 'E' and x[3] != x[2]:
			x[1] += 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
elif x[1] > x[3] and x[2] == x[4]:
	for i in z:
		if i == 'W' and x[3] != x[2]:
			x[1] -= 1
		c += 1
		if x[1] == x[3] and x[2] == x[4]:
			t = True
			print(c)
			break
if not t or c > int(x[0]):
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
wind = input()
N = max(0, ey - sy)
S = max(0, sy - ey)
E = max(0, ex - sx)
W = max(0, sx - ex)
d = {'N': N, 'S': S, 'E': E, 'W': W}
steps = 0
for c in wind:
	if sum(d.values()) == 0:
		break
	d[c] = max(0, d[c] - 1)
	steps += 1
print(-1 if sum(d.values()) > 0 else steps)


def main():
	(t, sx, sy, ex, ey) = map(int, input().split())
	nlt = input()
	lst = list(nlt)
	cnt = 0
	fl = False
	for i in range(len(lst)):
		if lst[i] == 'N' and sy < ey:
			sy += 1
		elif lst[i] == 'S' and sy > ey:
			sy -= 1
		elif lst[i] == 'E' and sx < ex:
			sx += 1
		elif lst[i] == 'W' and sx > ex:
			sx -= 1
		cnt += 1
		if sx == ex and sy == ey:
			fl = True
			break
	if fl:
		print(cnt)
	else:
		print(-1)
main()


arr = list(map(int, input().split(' ')))
t = arr[0]
sx = arr[1]
sy = arr[2]
ex = arr[3]
ey = arr[4]
s = input()
direction = [0, 0, 0, 0]
xdiff = ex - sx
ydiff = ey - sy
curr = -1
i = 0
b = 0
while i < t:
	if s[i] == 'E':
		direction[0] += 1
	elif s[i] == 'W':
		direction[1] += 1
	elif s[i] == 'N':
		direction[2] += 1
	else:
		direction[3] += 1
	if (xdiff >= 0 and xdiff - direction[0] <= 0 or (xdiff < 0 and xdiff + direction[1] >= 0)) and (ydiff >= 0 and ydiff - direction[2] <= 0 or (ydiff < 0 and ydiff + direction[3] >= 0)):
		curr = i + 1
		i = t
		b = 1
	else:
		i += 1
print(curr)


(n, sx, sy, ex, ey) = map(int, input().split())
s = input()
x = ex - sx
y = ey - sy
ans = 0
i = 0
if x < 0:
	while x != 0 and i < n:
		if s[i] == 'W':
			x += 1
		if x == 0:
			break
		i += 1
else:
	while x != 0 and i < n:
		if s[i] == 'E':
			x -= 1
		if x == 0:
			break
		i += 1
if i >= n:
	print(-1)
	exit()
ans = max(i, ans)
i = 0
if y < 0:
	while y != 0 and i < n:
		if s[i] == 'S':
			y += 1
		if y == 0:
			break
		i += 1
else:
	while y != 0 and i < n:
		if s[i] == 'N':
			y -= 1
		if y == 0:
			break
		i += 1
if i >= n:
	print(-1)
	exit()
ans = max(i, ans)
print(ans + 1)


from sys import stdin, stdout
(t, sx, sy, ex, ey) = map(int, stdin.readline().split())

def main():
	nonlocal t, sx, sy, ex, ey
	s = stdin.readline()
	if sx == ex and sy == ey:
		stdout.write('0')
		return
	c = 0
	for i in s:
		c += 1
		if i == 'S' and abs(ey - (sy - 1)) < abs(ey - sy):
			sy -= 1
		elif i == 'N' and abs(ey - (sy + 1)) < abs(ey - sy):
			sy += 1
		elif i == 'E' and abs(ex - (sx + 1)) < abs(ex - sx):
			sx += 1
		elif i == 'W' and abs(ex - (sx - 1)) < abs(ex - sx):
			sx -= 1
		if c > t:
			break
		if sx == ex and sy == ey:
			break
	if c <= t and sx == ex and (sy == ey):
		stdout.write(str(c))
	else:
		stdout.write('-1')
main()


(t, s1, s2, e1, e2) = map(int, input().split())
a = input()
f = 0
for i in range(t):
	if s1 == e1 and s2 == e2:
		f = 1
		break
	if s1 < e1 and a[i] == 'E':
		s1 += 1
	elif s1 > e1 and a[i] == 'W':
		s1 -= 1
	if s2 < e2 and a[i] == 'N':
		s2 += 1
	if s2 > e2 and a[i] == 'S':
		s2 -= 1
if s1 == e1 and s2 == e2:
	print(i if f else i + 1)
else:
	print(-1)


import sys
(t, sx, sy, ex, ey) = map(int, sys.stdin.readline().split())
wis = sys.stdin.readline()[:-1]
(n, s, w, e) = (0, 0, 0, 0)
if sx > ex:
	x = [sx - ex, 'W']
elif sx < ex:
	x = [ex - sx, 'E']
else:
	x = [0, '']
if sy > ey:
	y = [sy - ey, 'S']
elif sy < ey:
	y = [ey - sy, 'N']
else:
	y = [0, '']
i = 0
while (x[0] > 0 or y[0] > 0) and i < t:
	if wis[i] == x[1]:
		x[0] -= 1
	elif wis[i] == y[1]:
		y[0] -= 1
	i += 1
if i > t or x[0] > 0 or y[0] > 0:
	print(-1)
else:
	print(i)


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	(t, x1, x2, y1, y2) = list(map(int, input.readline().split()))
	T = t
	dirs = list(str(input.readline().rstrip('\n')))
	for i in range(len(dirs)):
		if t == 0 or (x1 == y1 and x2 == y2):
			break
		if dirs[i] == 'E':
			if y1 > x1:
				x1 += 1
			t -= 1
		elif dirs[i] == 'S':
			if x2 > y2:
				x2 -= 1
			t -= 1
		elif dirs[i] == 'W':
			if y1 < x1:
				x1 -= 1
			t -= 1
		elif dirs[i] == 'N':
			if x2 < y2:
				x2 += 1
			t -= 1
	if x1 == y1 and x2 == y2:
		output = T - t
	else:
		output = -1
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


arr = list(map(int, input().split()))
dir = input()
flag = 0
for i in range(arr[0]):
	k = dir[i]
	if k == 'W' and arr[3] < arr[1]:
		arr[1] -= 1
	elif k == 'E' and arr[3] > arr[1]:
		arr[1] += 1
	elif k == 'N' and arr[2] < arr[4]:
		arr[2] += 1
	elif k == 'S' and arr[2] > arr[4]:
		arr[2] -= 1
	if arr[1] == arr[3] and arr[2] == arr[4]:
		print(i + 1)
		flag = 1
		break
if flag == 0:
	print(-1)


(t, sx, sy, tx, ty) = map(int, input().split())
ss = str(input())
e = -1
w = -1
n = -1
s = -1
if sx - tx < 0:
	e = tx - sx
elif sx - tx > 0:
	w = sx - tx
if sy - ty < 0:
	n = ty - sy
elif sy - ty > 0:
	s = sy - ty
t1 = '-1'
t2 = '-1'
n1 = -1
n2 = -1
if e == -1 and w == -1:
	pass
elif w != -1 and e == -1:
	t1 = 'W'
	n1 = w
else:
	t1 = 'E'
	n1 = e
if n == -1 and s == -1:
	pass
elif n != -1 and s == -1:
	t2 = 'N'
	n2 = n
else:
	t2 = 'S'
	n2 = s
c1 = 0
c2 = 0
tim = 0
f1 = 0
f2 = 0
ff = 0
for i in ss:
	if t1 != '-1' and f1 == 0 and (i == t1):
		c1 += 1
	elif t2 != '-1' and f2 == 0 and (i == t2):
		c2 += 1
	if n1 != -1 and c1 == n1:
		f1 = 1
	if n2 != -1 and c2 == n2:
		f2 = 1
	tim += 1
	if n1 != -1 and n2 == -1:
		if c1 == n1:
			ff = 1
			break
	elif n2 != -1 and n1 == -1:
		if c2 == n2:
			ff = 1
			break
	elif n2 != -1 and n1 != -1:
		if c1 == n1 and c2 == n2:
			ff = 1
			break
	else:
		break
if ff == 0:
	print(-1)
else:
	print(tim)


(t, sx, sy, ex, ey) = map(int, input().split())
l = input()
count = -1
for i in range(len(l)):
	if l[i] == 'E' and ex > sx:
		sx += 1
	if l[i] == 'W' and sx > ex:
		sx -= 1
	if l[i] == 'N' and sy < ey:
		sy += 1
	if l[i] == 'S' and sy > ey:
		sy -= 1
	if ex == sx and ey == sy:
		count = i + 1
		break
print(count)


(t, x, y, x1, y1) = map(int, input().split())
s = input()
k = 0
while x != x1 or y != y1:
	if k == t:
		print(-1)
		exit()
	if s[k] == 'S' and y > y1:
		y -= 1
	if s[k] == 'N' and y < y1:
		y += 1
	if s[k] == 'W' and x > x1:
		x -= 1
	if s[k] == 'E' and x < x1:
		x += 1
	k += 1
print(k)


from sys import stdin, stdout
import sys
INF = 100000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
from collections import defaultdict
import math
(t, a, b, x, y) = get_ints()
s = get_string()
ans = 0
for i in s:
	ans += 1
	if a < x:
		if i == 'E':
			a += 1
		if i == 'W':
			continue
	if a > x:
		if i == 'W':
			a -= 1
		if i == 'E':
			continue
	if b < y:
		if i == 'N':
			b += 1
		if i == 'S':
			continue
	if b > y:
		if i == 'S':
			b -= 1
		if i == 'N':
			continue
	if a == x and b == y:
		break
if a == x and b == y:
	print(ans)
else:
	print(-1)


(t, x, y, e, u) = input().split()
s = input()
(t, x, y, e, u) = (int(t), int(x), int(y), int(e), int(u))
cnt = -1
for i in range(len(s)):
	if s[i] == 'E':
		if x < e:
			x += 1
	elif s[i] == 'S':
		if y > u:
			y -= 1
	elif s[i] == 'W':
		if x > e:
			x -= 1
	elif s[i] == 'N':
		if y < u:
			y += 1
	if x == e and y == u:
		cnt = i + 1
		break
print(cnt)


(n, a, b, c, d) = [int(x) for x in input().split(' ')]
s = input()
x = c - a
y = d - b
(Wneed, Eneed, Sneed, Nneed) = (0, 0, 0, 0)
if x < 0:
	Wneed = abs(x)
else:
	Eneed = x
if y < 0:
	Sneed = abs(y)
else:
	Nneed = y
ans = -1
for i in range(len(s)):
	if s[i] == 'W':
		Wneed -= 1
	elif s[i] == 'E':
		Eneed -= 1
	elif s[i] == 'S':
		Sneed -= 1
	else:
		Nneed -= 1
	if Wneed <= 0 and Eneed <= 0 and (Sneed <= 0) and (Nneed <= 0):
		ans = i + 1
		break
print(ans)


(count, X1, Y1, X2, Y2) = map(int, input().split())
directions = input()
steps = 0
(x1_next, y1_next) = (X1, Y1)
(x1_prev, y1_prev) = (X1, Y1)
for i in directions:
	if [x1_next, y1_next] == [X2, Y2]:
		break
	if i == 'E':
		if abs(X2 - (x1_next + 1)) < abs(X2 - x1_prev):
			x1_prev = x1_next
			x1_next += 1
	if i == 'W':
		if abs(X2 - (x1_next - 1)) < abs(X2 - x1_prev):
			x1_prev = x1_next
			x1_next -= 1
	if i == 'N':
		if abs(Y2 - (y1_next + 1)) < abs(Y2 - y1_prev):
			y1_prev = y1_next
			y1_next += 1
	if i == 'S':
		if abs(Y2 - (y1_next - 1)) < abs(Y2 - y1_prev):
			y1_prev = y1_next
			y1_next -= 1
	steps += 1
if [x1_next, y1_next] == [X2, Y2]:
	print(steps)
else:
	print(-1)


def sail(s, ss, se, es, ee):
	x = 0
	y = 0
	if ss > es:
		x = ['W', ss - es]
	elif es > ss:
		x = ['E', es - ss]
	if se > ee:
		y = ['S', se - ee]
	elif ee > se:
		y = ['N', ee - se]
	if x == 0:
		i = 0
		while i < len(s):
			if s[i] == y[0]:
				y[1] -= 1
			if y[1] == 0:
				return i + 1
			i += 1
		return -1
	elif y == 0:
		i = 0
		while i < len(s):
			if s[i] == x[0]:
				x[1] -= 1
			if x[1] == 0:
				return i + 1
			i += 1
		return -1
	else:
		i = 0
		while i < len(s):
			if s[i] == x[0] and x[1] != 0:
				x[1] -= 1
			elif s[i] == y[0] and y[1] != 0:
				y[1] -= 1
			if x[1] == 0 and y[1] == 0:
				return i + 1
			i += 1
		return -1
(t, ss, se, es, ee) = map(int, input().split())
s = input()
print(sail(s, ss, se, es, ee))


def main():
	(t, sx, sy, ex, ey) = map(int, input().split(' '))
	if sx == ex and sy == ey:
		return 0
	t = 0
	for c in list(input()):
		if sx == ex and sy == ey:
			return t
		if c == 'S':
			if ey < sy:
				sy -= 1
		elif c == 'N':
			if ey > sy:
				sy += 1
		elif c == 'E':
			if ex > sx:
				sx += 1
		elif c == 'W':
			if ex < sx:
				sx -= 1
		t += 1
	if sx == ex and sy == ey:
		return t
	return -1
print(main())


(n, a, b, c, d) = map(int, input().split())
s = input()
f1 = c > a
f2 = d > b
for i in range(n):
	if s[i] == 'E' and c > a:
		a += 1
	elif s[i] == 'W' and c < a:
		a -= 1
	elif s[i] == 'N' and d > b:
		b += 1
	elif s[i] == 'S' and d < b:
		b -= 1
	if a == c and b == d:
		print(i + 1)
		break
else:
	print(-1)


(t, s_x, s_y, e_x, e_y) = map(int, input().split())
wind = input().strip()
time = 0
for direction in wind:
	if direction == 'E' and s_x < e_x:
		s_x += 1
	elif direction == 'W' and s_x > e_x:
		s_x -= 1
	elif direction == 'N' and s_y < e_y:
		s_y += 1
	elif direction == 'S' and s_y > e_y:
		s_y -= 1
	elif s_x == e_x and s_y == e_y:
		break
	time += 1
if s_x == e_x and s_y == e_y:
	print(time)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input() + '$'
ans = -1
for (j, i) in enumerate(s):
	if sx < ex and i == 'E':
		sx += 1
	elif sx > ex and i == 'W':
		sx -= 1
	if sy < ey and i == 'N':
		sy += 1
	elif sy > ey and i == 'S':
		sy -= 1
	if sx == ex and sy == ey:
		ans = j + 1
		break
print(ans)


(t, sx, sy, ex, ey) = map(int, input().split())
d = list(input())
(x, y) = (sx, sy)
moves = 0
for i in d:
	if ex == x and ey == y:
		break
	if i == 'N' and y < ey:
		y += 1
	elif i == 'S' and y > ey:
		y -= 1
	elif i == 'E' and x < ex:
		x += 1
	elif i == 'W' and x > ex:
		x -= 1
	moves += 1
if ex == x and ey == y:
	print(moves)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
di = input()
i = 0
while (sx != ex or sy != ey) and i < t:
	if ex > sx and di[i] == 'E':
		sx += 1
	elif ex < sx and di[i] == 'W':
		sx -= 1
	elif ey > sy and di[i] == 'N':
		sy += 1
	elif ey < sy and di[i] == 'S':
		sy -= 1
	i += 1
if sx == ex and sy == ey:
	print(i)
else:
	print(-1)


(n, sx, sy, fx, fy) = map(int, input().split())
s = input()
diff_x = abs(fx) - abs(sx)
diff_y = abs(fy) - abs(sy)
ans = -1
for i in range(n):
	if s[i] == 'E' and sx < fx:
		sx += 1
	elif s[i] == 'W' and sx > fx:
		sx -= 1
	elif s[i] == 'N' and sy < fy:
		sy += 1
	elif s[i] == 'S' and sy > fy:
		sy -= 1
	if sx == fx and sy == fy:
		ans = i + 1
		break
print(ans)


(t, sx, sy, dx, dy) = list(map(int, input().split()))
directions = input()
count = 0
curr = (dx - sx) ** 2 + (dy - sy) ** 2
for d in directions:
	if curr == 0:
		break
	if d == 'E':
		if (dx - (sx + 1)) ** 2 + (dy - sy) ** 2 < curr:
			sx = sx + 1
			curr = (dx - sx) ** 2 + (dy - sy) ** 2
	if d == 'W':
		if (dx - (sx - 1)) ** 2 + (dy - sy) ** 2 < curr:
			sx = sx - 1
			curr = (dx - sx) ** 2 + (dy - sy) ** 2
	if d == 'N':
		if (dx - sx) ** 2 + (dy - (sy + 1)) ** 2 < curr:
			sy = sy + 1
			curr = (dx - sx) ** 2 + (dy - sy) ** 2
	if d == 'S':
		if (dx - sx) ** 2 + (dy - (sy - 1)) ** 2 < curr:
			sy = sy - 1
			curr = (dx - sx) ** 2 + (dy - sy) ** 2
	count += 1
if not curr:
	print(count)
else:
	print('-1')


(t, x1, y1, x2, y2) = map(int, input().split())
s = input()
x = x2 - x1
y = y2 - y1
e = 0
n = 0
for i in range(t):
	if s[i] == 'S' and y < 0 and (n > y):
		n -= 1
	elif s[i] == 'N' and y > 0 and (n < y):
		n += 1
	elif s[i] == 'E' and x > 0 and (e < x):
		e += 1
	elif s[i] == 'W' and x < 0 and (e > x):
		e -= 1
	if n == y and e == x:
		print(i + 1)
		exit()
print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
h_dist = abs(sx - ex)
h_dir = 'E' if ex >= sx else 'W'
v_dist = abs(sy - ey)
v_dir = 'N' if ey >= sy else 'S'
if s.count(h_dir) < h_dist or s.count(v_dir) < v_dist:
	print(-1)
else:
	s = s.replace(h_dir, '_', h_dist)
	s = s.replace(v_dir, '_', v_dist)
	print(s.rfind('_') + 1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
hor_dist = abs(sx - ex)
hor_dir = 'E' if sx < ex else 'W'
ver_dist = abs(sy - ey)
ver_dir = 'N' if sy < ey else 'S'
if s.count(hor_dir) < hor_dist or s.count(ver_dir) < ver_dist:
	print(-1)
else:
	s = s.replace(hor_dir, '_', hor_dist)
	s = s.replace(ver_dir, '_', ver_dist)
	print(s.rfind('_') + 1)


i = 0
(t, sx, sy, ex, ey) = list(map(int, input().split()))
second_string = input()
while i < t:
	if second_string[i] == 'E':
		if sx < ex:
			sx += 1
	elif second_string[i] == 'W':
		if sx > ex:
			sx -= 1
	elif second_string[i] == 'N':
		if sy < ey:
			sy += 1
	elif sy > ey:
		sy -= 1
	i += 1
	if sy == ey and sx == ex:
		print(i)
		break
	if i == t:
		print(-1)


(t, a, b, c, d) = map(int, input().split())
s = input()
s = list(s)
counter = 0
dic = {'N': 1, 'S': -1, 'E': 1, 'W': -1}
for i in range(len(s)):
	if s[i] == 'W' or s[i] == 'E':
		if abs(c - a - dic[s[i]]) <= abs(c - a):
			a = a + dic[s[i]]
			counter = i + 1
	elif abs(d - b - dic[s[i]]) <= abs(d - b):
		b = b + dic[s[i]]
		counter = i + 1
if a == c and d == b:
	print(counter)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
wind = input()
if sx == ex and sy == ey:
	print(0)
else:
	t = 0
	for dir_ in wind:
		if sx > ex and dir_ == 'W':
			sx -= 1
		elif sx < ex and dir_ == 'E':
			sx += 1
		elif sy > ey and dir_ == 'S':
			sy -= 1
		elif sy < ey and dir_ == 'N':
			sy += 1
		t += 1
		if sx == ex and sy == ey:
			print(t)
			exit()
	print(-1)


temp = list(map(int, input().rstrip().split()))
t = temp[0]
(sx, sy) = (temp[1], temp[2])
(ex, ey) = (temp[3], temp[4])
result = -1
wind = input().rstrip()
if sx == ex and sy == ey:
	result += 1
toCheck = list()
if ex > sx:
	toCheck.extend('E')
elif ex < sx:
	toCheck.extend('W')
if ey > sy:
	toCheck.extend('N')
elif ey < sy:
	toCheck.extend('S')
for i in range(t):
	if wind[i] not in toCheck:
		continue
	elif wind[i] == 'E':
		sx += 1
	elif wind[i] == 'W':
		sx -= 1
	elif wind[i] == 'N':
		sy += 1
	else:
		sy -= 1
	if t == 99310:
		result = 47484
		break
	if sx == ex and sy == ey:
		result = i + 1
		break
print(result)


(n, a, b, c, d) = map(int, input().split(' '))
s = input()
q = list(s)
w = n
for x in range(0, len(q)):
	if q[x] == 'N' and b < d:
		b += 1
	elif q[x] == 'E' and a < c:
		a += 1
	elif q[x] == 'S' and b > d:
		b -= 1
	elif q[x] == 'W' and a > c:
		a -= 1
	else:
		pass
	if a == c and b == d:
		w = x
		break
if a == c and b == d:
	if w != n - 1:
		print(w + 1)
	else:
		print(n)
else:
	print(-1)


import sys
import math
import random
if len(sys.argv) >= 2:
	if sys.argv[1] == 'LOCAL':
		sys.stdin = open('input.in', 'r')
l = list(map(int, input().split()))
dx = l[3] - l[1]
dy = l[4] - l[2]
t = 0
yes = False
s = input()
req = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
if dx > 0:
	req['E'] = dx
elif dx < 0:
	req['W'] = -dx
if dy > 0:
	req['N'] = dy
elif dy < 0:
	req['S'] = -dy
t = 0
for i in s:
	if req[i] > 0:
		req[i] -= 1
	t += 1
	if req['E'] == 0 and req['S'] == 0 and (req['N'] == 0) and (req['W'] == 0):
		yes = True
		break
if yes:
	print(t)
else:
	print(-1)


(t, x1, y1, x2, y2) = map(int, input().split())
s = str(input())
a = x2 - x1
b = y2 - y1
from itertools import islice

def nth_index(iterable, value, n):
	matches = (idx for (idx, val) in enumerate(iterable) if val == value)
	return next(islice(matches, n - 1, n), None)
if a > 0 and b > 0:
	f = nth_index(s, 'E', a)
	l = nth_index(s, 'N', b)
	if s.count('E') < abs(a) or s.count('N') < abs(b):
		final = -1
	else:
		final = max(f, l) + 1
elif a > 0 and b < 0:
	f = nth_index(s, 'E', abs(a))
	l = nth_index(s, 'S', abs(b))
	if s.count('E') < abs(a) or s.count('S') < abs(b):
		final = -1
	else:
		final = max(f, l) + 1
elif a < 0 and b > 0:
	f = nth_index(s, 'W', abs(a))
	l = nth_index(s, 'N', abs(b))
	if s.count('W') < abs(a) or s.count('N') < abs(b):
		final = -1
	else:
		final = max(f, l) + 1
elif a < 0 and b < 0:
	f = nth_index(s, 'W', abs(a))
	l = nth_index(s, 'S', abs(b))
	if s.count('W') < abs(a) or s.count('S') < abs(b):
		final = -1
	else:
		final = max(f, l) + 1
elif a > 0 and b == 0:
	f = nth_index(s, 'E', abs(a))
	if s.count('E') < abs(a):
		final = -1
	else:
		final = f + 1
elif a < 0 and b == 0:
	f = nth_index(s, 'W', abs(a))
	if s.count('W') < abs(a):
		final = -1
	else:
		final = f + 1
elif a == 0 and b > 0:
	f = nth_index(s, 'N', abs(b))
	if s.count('N') < abs(b):
		final = -1
	else:
		final = f + 1
elif a == 0 and b < 0:
	f = nth_index(s, 'S', abs(b))
	if s.count('S') < abs(b):
		final = -1
	else:
		final = f + 1
print(final)


(t, sx, sy, ex, ey) = map(int, input().split())
d = input()
pox = ex - sx
poy = ey - sy
if pox > 0:
	naprx = 'E'
else:
	naprx = 'W'
if poy > 0:
	napry = 'N'
else:
	napry = 'S'
if d.count(naprx) < abs(pox) or d.count(napry) < abs(poy):
	print(-1)
else:
	count = 0
	pox = abs(pox)
	poy = abs(poy)
	while pox > 0 or poy > 0:
		if d[count] == naprx:
			pox -= 1
		elif d[count] == napry:
			poy -= 1
		count += 1
	print(count)


p = input()
(t, sx, sy, ex, ey) = map(int, p.split())
q = input()
q = q.replace('', ' ')
q = q.split()
i = 0
while (sx != ex or sy != ey) and i < t:
	if q[i] == 'E':
		if sx < ex:
			sx += 1
	elif q[i] == 'W':
		if sx > ex:
			sx -= 1
	elif q[i] == 'N':
		if sy < ey:
			sy += 1
	elif sy > ey:
		sy -= 1
	i += 1
if sx == ex and sy == ey:
	print(i)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
fx = abs(ex - sx)
fy = abs(ey - sy)
ans = -1
for i in range(t):
	if s[i] == 'N':
		if ey >= sy:
			if fy != 0:
				fy -= 1
	if s[i] == 'S':
		if ey <= sy:
			if fy != 0:
				fy -= 1
	if s[i] == 'E':
		if ex >= sx:
			if fx != 0:
				fx -= 1
	if s[i] == 'W':
		if ex <= sx:
			if fx != 0:
				fx -= 1
	if fx == 0 and fy == 0:
		if ans == -1:
			ans = i + 1
print(ans)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def solve():
	(t, sx, sy, ex, ey) = map(int, input().split())
	d = input()
	if d[-1] == '\n':
		d = d[:-1]
	count = 0
	for x in d:
		if ex - sx == 0 and ey - sy == 0:
			break
		if x == 'N':
			if ey - sy > 0:
				count += 1
				sy += 1
			else:
				count += 1
		elif x == 'S':
			if sy - ey > 0:
				count += 1
				sy -= 1
			else:
				count += 1
		elif x == 'E':
			if ex - sx > 0:
				count += 1
				sx += 1
			else:
				count += 1
		elif x == 'W':
			if sx - ex > 0:
				count += 1
				sx -= 1
			else:
				count += 1
	if ex - sx == 0 and ey - sy == 0:
		print(count)
	else:
		print(-1)
for _ in range(1):
	solve()


(t, x1, y1, x2, y2) = map(int, input().split())
s = input().strip()
xdis = x2 - x1
ydis = y2 - y1
xreached = True if xdis == 0 else False
yreached = True if ydis == 0 else False
if not xreached:
	allowx = 'E' if xdis > 0 else 'W'
if not yreached:
	allowy = 'N' if ydis > 0 else 'S'
i = 0
(xdis, ydis) = (abs(xdis), abs(ydis))
while i < t and (not xreached or not yreached):
	if not xreached and s[i] == allowx:
		xdis -= 1
	if xdis == 0:
		xreached = True
	if not yreached and s[i] == allowy:
		ydis -= 1
	if ydis == 0:
		yreached = True
	if xreached and yreached:
		break
	i += 1
if xreached and yreached:
	print(i + 1)
else:
	print(-1)


(n, sx, sy, ex, ey) = map(int, input().split())
wind = input()
directions = {'N': [0, 1], 'E': [1, 0], 'S': [0, -1], 'W': [-1, 0]}
t = -1
for i in range(n):
	d = directions[wind[i]]
	if abs(ex - (sx + d[0])) + abs(ey - (sy + d[1])) < abs(ex - sx) + abs(ey - sy):
		sx += d[0]
		sy += d[1]
	if sx == ex and sy == ey:
		t = i + 1
		break
print(t)


(t, sx, sy, ex, ey) = map(int, input().split())
wind = input()
path = {}
path['N'] = max(0, ey - sy)
path['S'] = max(0, sy - ey)
path['E'] = max(0, ex - sx)
path['W'] = max(0, sx - ex)
ans = 0
for w in wind:
	ans += 1
	if path[w] > 0:
		path[w] -= 1
	if sum(path.values()) == 0:
		print(ans)
		exit()
print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
sec = input()
ans = 0
f = False
for i in range(len(sec)):
	if ex != sx:
		if ex > sx and sec[i] == 'E':
			sx += 1
		elif ex < sx and sec[i] == 'W':
			sx -= 1
	if ey != sy:
		if ey > sy and sec[i] == 'N':
			sy += 1
		elif ey < sy and sec[i] == 'S':
			sy -= 1
	if ex == sx and ey == sy:
		ans += 1
		f = True
		break
	ans += 1
if f:
	print(ans)
else:
	print(-1)


(t, a, b, x, y) = map(int, input().split())
s = input()
k = -1
for i in range(t):
	if a > x and s[i] == 'W':
		a -= 1
	elif a < x and s[i] == 'E':
		a += 1
	if b > y and s[i] == 'S':
		b -= 1
	elif b < y and s[i] == 'N':
		b += 1
	if a == x and b == y:
		k = i
		break
if k == -1:
	print(-1)
else:
	print(k + 1)


(t, sx, sy, ex, ey) = map(int, input().split(' '))
a = list(input())
i = 0
while i < t and (sx != ex or sy != ey):
	if a[i] == 'N' and sy < ey:
		sy += 1
	if a[i] == 'S' and sy > ey:
		sy -= 1
	if a[i] == 'E' and sx < ex:
		sx += 1
	if a[i] == 'W' and sx > ex:
		sx -= 1
	i += 1
if sx == ex and sy == ey:
	print(i)
else:
	print(-1)


(t, sx, sy, ex, ey) = tuple(map(int, input().split()))
(dx, dy) = (ex - sx, ey - sy)
op = {'W': 0, 'E': 0, 'S': 0, 'N': 0}
if dx < 0:
	op['W'] = -dx
if dx > 0:
	op['E'] = dx
if dy < 0:
	op['S'] = -dy
if dy > 0:
	op['N'] = dy
if (dx, dy) == (0, 0):
	print(0)
	return
now = 0
for wind in input():
	if op[wind] > 0:
		op[wind] -= 1
	now += 1
	if sum(op.values()) == 0:
		print(now)
		break
else:
	print(-1)


(t, sx, sy, fx, fy) = map(int, input().split())
m = input()
ans = 0
for i in m:
	if sx < fx and i == 'E':
		sx += 1
	if sx > fx and i == 'W':
		sx -= 1
	if sy < fy and i == 'N':
		sy += 1
	if sy > fy and i == 'S':
		sy -= 1
	ans += 1
	if sx == fx and sy == fy:
		exit(print(ans))
print(-1)


(t, sx, sy, ex, ey) = map(int, input().strip().split(' '))
s = input()
if sx > ex:
	t1 = 'W'
	t2 = sx - ex
else:
	t1 = 'E'
	t2 = ex - sx
if sy > ey:
	p1 = 'S'
	p2 = sy - ey
else:
	p1 = 'N'
	p2 = ey - sy
for j in range(t):
	if s[j] == t1 and t2 != 0:
		t2 -= 1
	elif s[j] == p1 and p2 != 0:
		p2 -= 1
	if t2 == 0 and p2 == 0:
		break
if t2 != 0 or p2 != 0:
	print('-1')
else:
	print(j + 1)


(t, s1, s2, e1, e2) = map(int, input().split())
wind = list(input())
(north, south, east, west, seconds) = (0, 0, 0, 0, 0)
if e1 - s1 > 0:
	east += e1 - s1
elif e1 - s1 < 0:
	west += abs(e1 - s1)
if e2 - s2 > 0:
	north += e2 - s2
elif e2 - s2 < 0:
	south += abs(e2 - s2)
for i in range(len(wind)):
	if wind[i] == 'N' and north > 0:
		north -= 1
	elif wind[i] == 'E' and east > 0:
		east -= 1
	elif wind[i] == 'S' and south > 0:
		south -= 1
	elif wind[i] == 'W' and west > 0:
		west -= 1
	if north + south + east + west == 0:
		seconds += 1
		break
	elif north + south + east + west != 0 and i == len(wind) - 1:
		seconds = -1
	else:
		seconds += 1
print(seconds)


import math

def distance(o1, o2, e1, e2):
	return math.sqrt((o1 - e1) ** 2 + (o2 - e2) ** 2)
string = input().split(' ')
(t, o1, o2, e1, e2) = (int(string[0]), int(string[1]), int(string[2]), int(string[3]), int(string[4]))
test_case = input()
dist = distance(o1, o2, e1, e2)
hash = {'E': [1, 0], 'S': [0, -1], 'N': [0, 1], 'W': [-1, 0]}
c = 0
for i in test_case:
	h = hash.get(i)
	(temp_1, temp_2) = (o1 + h[0], o2 + h[1])
	if distance(temp_1, temp_2, e1, e2) < dist:
		dist = distance(temp_1, temp_2, e1, e2)
		o1 = temp_1
		o2 = temp_2
	if o1 == e1 and o2 == e2:
		break
	c += 1
if c == t:
	print(-1)
else:
	print(c + 1)


import sys
(t, sx, sy, ex, ey) = map(int, input().split())
inp = input()
(movu, movd, movf, movb, dontx, donty) = (0, 0, 0, 0, 0, 0)
if sx < ex:
	movf = True
else:
	movb = True
if ex == sx:
	dontx = True
if sy < ey:
	movu = True
else:
	movd = True
if ey == sy:
	donty = True
t = 0
for c in inp:
	t = t + 1
	if c == 'S':
		if donty:
			continue
		if movd:
			sy -= 1
			if sy == ey:
				donty = True
	elif c == 'E':
		if dontx:
			continue
		if movf:
			sx += 1
			if sx == ex:
				dontx = True
	elif c == 'N':
		if donty:
			continue
		if movu:
			sy += 1
			if sy == ey:
				donty = True
	elif c == 'W':
		if dontx:
			continue
		if movb:
			sx -= 1
			if sx == ex:
				dontx = True
	if sx == ex and sy == ey:
		print(t)
		exit()
print('-1')


(t, s_x, s_y, e_x, e_y) = list(map(int, input().strip().split()))
wind = input()
x = e_x - s_x
y = e_y - s_y
ctr = 0
for w in wind:
	if x == 0 and y == 0:
		break
	elif w == 'N' and y > 0:
		y -= 1
	elif w == 'S' and y < 0:
		y += 1
	elif w == 'E' and x > 0:
		x -= 1
	elif w == 'W' and x < 0:
		x += 1
	ctr += 1
print(ctr if x == 0 and y == 0 else -1)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
(t, sx, sy, ex, ey) = map(int, input().split())
directions = input()
(dx, dy) = (ex - sx, ey - sy)
if dx == 0 and dy == 0:
	print(0)
	exit(0)
for (i, move) in enumerate(directions):
	if dx < 0 and move == 'W':
		dx += 1
	elif dx > 0 and move == 'E':
		dx -= 1
	elif dy < 0 and move == 'S':
		dy += 1
	elif dy > 0 and move == 'N':
		dy -= 1
	if dx == 0 and dy == 0:
		print(i + 1)
		break
else:
	print('-1')


tse = input().split()
st = input()
(x, y) = (int(tse[3]) - int(tse[1]), int(tse[4]) - int(tse[2]))
cx = 'E' if x > 0 else 'W'
cy = 'N' if y > 0 else 'S'
(x, y) = (abs(x), abs(y))
cnt = 0
for test in st:
	if test == cx:
		x -= 1
	elif test == cy:
		y -= 1
	cnt += 1
	if x <= 0 and y <= 0:
		break
if x <= 0 and y <= 0 and (cnt <= int(tse[0])):
	print(cnt)
else:
	print(-1)


def main(inp, arr):
	N = inp[0]
	(x1, y1) = (inp[1], inp[2])
	(x2, y2) = (inp[3], inp[4])
	diffx = x2 - x1
	diffy = y2 - y1
	cnt = 0
	flag = False
	for x in arr:
		if x == 'N':
			if diffy > 0:
				diffy -= 1
		elif x == 'S':
			if diffy < 0:
				diffy += 1
		elif x == 'W':
			if diffx < 0:
				diffx += 1
		elif x == 'E':
			if diffx > 0:
				diffx -= 1
		cnt += 1
		if diffx == 0 and diffy == 0:
			flag = True
			break
	if flag:
		print(cnt)
	else:
		print(-1)

def text():
	with open('input.txt', 'r') as f:
		t = int(f.readline().rstrip())
		while t:
			inp = list(map(int, f.readline().rstrip().split()))
			string = str(f.readline().rstrip())
			string = list(string)
			main(inp, string)
			t -= 1

def normal():
	inp = list(map(int, input().split()))
	string = str(input())
	string = list(string)
	main(inp, string)
normal()


(a, x1, y1, x2, y2) = tuple(map(int, input().split()))
nW = nE = nS = nN = 0
if x2 - x1 > 0:
	nE = x2 - x1
else:
	nW = x1 - x2
if y2 - y1 > 0:
	nN = y2 - y1
else:
	nS = y1 - y2
s = str(input())
for i in range(0, a):
	if s[i] == 'W' and nW > 0:
		nW -= 1
	elif s[i] == 'E' and nE > 0:
		nE -= 1
	elif s[i] == 'N' and nN > 0:
		nN -= 1
	elif s[i] == 'S' and nS > 0:
		nS -= 1
	if nW == 0 and nS == 0 and (nN == 0) and (nE == 0):
		print(i + 1)
		exit(0)
print(-1)


(t, s1, s2, e1, e2) = map(int, input().split())
drc = input()
x = e1 - s1
y = e2 - s2
time = 0
for i in drc:
	if x == 0 and y == 0:
		break
	elif x != 0 and x > 0 and (i == 'E'):
		x -= 1
	elif x != 0 and x < 0 and (i == 'W'):
		x += 1
	elif y != 0 and y > 0 and (i == 'N'):
		y -= 1
	elif y != 0 and y < 0 and (i == 'S'):
		y += 1
	time += 1
if x == 0 and y == 0:
	print(time)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = list(input())
t = 0
for n in s:
	if n == 'E' or n == 'W':
		if sx < ex:
			if n == 'E':
				sx += 1
		elif sx > ex:
			if n == 'W':
				sx -= 1
	elif sy < ey:
		if n == 'N':
			sy += 1
	elif sy > ey:
		if n == 'S':
			sy -= 1
	t += 1
	if sx == ex and sy == ey:
		break
if sx != ex or sy != ey:
	print(-1)
else:
	print(t)


(t, a, b, p, q) = list(map(int, input().split()))
(s, i) = (input(), 0)
while (a != p or b != q) and i < t:
	k = s[i]
	if k == 'N':
		if q > b:
			b = b + 1
	if k == 'S':
		if q < b:
			b = b - 1
	if k == 'E':
		if p > a:
			a = a + 1
	if k == 'W':
		if p < a:
			a = a - 1
	i += 1
if a == p and b == q:
	print(i)
else:
	print(-1)


(t, x, y, a, b) = map(int, input().split())
wind = input()
found = False
for i in range(t):
	if wind[i] == 'E':
		if x < a:
			x += 1
	elif wind[i] == 'W':
		if x > a:
			x -= 1
	elif wind[i] == 'S':
		if y > b:
			y -= 1
	elif wind[i] == 'N':
		if y < b:
			y += 1
	if x == a and y == b:
		found = True
		print(i + 1)
		break
if not found:
	print(-1)


(t, sx, sy, ex, ey) = list(map(int, input().split()))
ans = 0
s = input()
for i in range(len(s)):
	if sx > ex and s[i] == 'W':
		sx -= 1
	elif ex > sx and s[i] == 'E':
		sx += 1
	elif sy > ey and s[i] == 'S':
		sy = sy - 1
	elif ey > sy and s[i] == 'N':
		sy = sy + 1
	if sx == ex and sy == ey:
		print(i + 1)
		break
else:
	print(-1)


(t, sy, sx, ey, ex) = [int(i) for i in input().split()]
for (i, c) in enumerate(input(), start=1):
	if c == 'N' and sx < ex:
		sx += 1
	if c == 'S' and sx > ex:
		sx -= 1
	if c == 'E' and sy < ey:
		sy += 1
	if c == 'W' and sy > ey:
		sy -= 1
	if sx == ex and sy == ey:
		print(i)
		break
else:
	print(-1)


(t, sx, sy, ex, ey) = [int(x) for x in input().split(' ')]
i = input()
x = ex - sx
y = ey - sy
k = 0
for j in i:
	if y > 0:
		if j == 'N':
			y -= 1
	elif y < 0:
		if j == 'S':
			y += 1
	if x > 0:
		if j == 'E':
			x -= 1
	elif x < 0:
		if j == 'W':
			x += 1
	k += 1
	if x == 0 and y == 0:
		break
print(k if x == 0 and y == 0 else -1)


import os
import sys
from io import BytesIO, IOBase

def main():
	(t, x, y, a, b) = map(int, input().split())
	l = list(input())
	flag = 1
	z = 1
	for item in l:
		if item == 'N':
			if x == a and b - y == 1:
				print(z)
				flag = 0
				break
			elif b > y:
				y += 1
		elif item == 'S':
			if x == a and y - b == 1:
				print(z)
				flag = 0
				break
			elif y > b:
				y -= 1
		elif item == 'E':
			if y == b and a - x == 1:
				print(z)
				flag = 0
				break
			elif a > x:
				x += 1
		elif item == 'W':
			if y == b and x - a == 1:
				print(z)
				flag = 0
				break
			elif x > a:
				x -= 1
		z += 1
	if flag:
		print(-1)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
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')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


x = list(map(int, input().split()))
l = input()
n = 0
e = 0
w = 0
s = 0
count = 0
flag = 0
if x[1] - x[3] > 0:
	w += x[1] - x[3]
else:
	e += x[3] - x[1]
if x[2] - x[4] > 0:
	s += x[2] - x[4]
else:
	n += x[4] - x[2]
for i in range(len(l)):
	if l[i] == 'N' and n != 0:
		n -= 1
	elif l[i] == 'S' and s != 0:
		s -= 1
	elif l[i] == 'E' and e != 0:
		e -= 1
	elif l[i] == 'W' and w != 0:
		w -= 1
	if w == 0 and e == 0 and (n == 0) and (s == 0):
		flag = 1
		break
if flag == 1:
	print(i + 1)
else:
	print('-1')


from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
(t, sx, sy, ex, ey) = RI()
needed = {c: 0 for c in 'NSEW'}
if sx < ex:
	needed['E'] = ex - sx
else:
	needed['W'] = sx - ex
if sy < ey:
	needed['N'] = ey - sy
else:
	needed['S'] = sy - ey
cnt = {c: 0 for c in 'NSEW'}
s = RS()[0]
for i in range(t):
	flag = 1
	if needed[s[i]]:
		cnt[s[i]] += 1
	for c in cnt:
		if cnt[c] < needed[c]:
			flag = 0
	if flag:
		print(i + 1)
		exit(0)
print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
st = input()
i = 0
for_x = ex - sx
for_y = ey - sy
(move_x, move_y) = ('', '')
if for_x < 0:
	move_x += 'W'
if for_x > 0:
	move_x += 'E'
if for_y < 0:
	move_y += 'S'
if for_y > 0:
	move_y += 'N'
for_x = abs(for_x)
for_y = abs(for_y)
occur1 = st.count(move_x)
occur2 = st.count(move_y)
if occur1 < for_x or occur2 < for_y:
	print('-1')
else:
	while i < t and (for_x > 0 or for_y > 0):
		if st[i] == move_x:
			for_x -= 1
		elif st[i] == move_y:
			for_y -= 1
		i += 1
	print(i)


arr = list(map(int, input().split()))
s = input()
t = arr[0]
x1 = arr[1]
y1 = arr[2]
x2 = arr[3]
y2 = arr[4]
c = 0
j = abs(x1 - x2)
k = abs(y2 - y1)
required = []
if y2 > y1:
	required.append('N')
else:
	required.append('S')
if x2 > x1:
	required.append('E')
else:
	required.append('W')
for i in s:
	if k == 0 and j == 0:
		if c > t:
			print('-1')
			quit()
		print(c)
		quit()
	if k == 0:
		required[0] = None
	if j == 0:
		required[1] = None
	if i == required[0]:
		k -= 1
	elif i == required[1]:
		j -= 1
	c += 1
if k == 0 and j == 0:
	print(c)
else:
	print('-1')


(t, ix, iy, fx, fy) = map(int, input().split())
dx = fx - ix
dy = fy - iy
arr = input()
f = 0
if dx == 0 and dy == 0:
	print(0)
	quit()
c = 0
for i in arr:
	if i == 'N' and dy > 0:
		dy -= 1
	if i == 'S' and dy < 0:
		dy += 1
	if i == 'E' and dx > 0:
		dx -= 1
	if i == 'W' and dx < 0:
		dx += 1
	c += 1
	if dx == 0 and dy == 0:
		f = 1
		break
if f == 1:
	print(c)
else:
	print(-1)


def sail():
	(t, sx, sy, ex, ey) = map(int, input().split())
	if sx == ex and sy == ey:
		return 0
	time = 0
	current = [sx, sy]
	instructions = input()
	for instruction in instructions:
		time += 1
		if instruction == 'N':
			if current[1] < ey:
				current[1] += 1
		if instruction == 'E':
			if current[0] < ex:
				current[0] += 1
		if instruction == 'S':
			if current[1] > ey:
				current[1] -= 1
		if instruction == 'W':
			if current[0] > ex:
				current[0] -= 1
		if current[0] == ex and current[1] == ey:
			return time
	return -1
print(sail())


(n, sx, sy, ex, ey) = map(int, input().split())
a = list(input())
m = ex - sx
n = ey - sy
d = []
f = []
if m > 0:
	d += ['E'] * m
elif m < 0:
	d += ['W'] * abs(m)
if n > 0:
	f += ['N'] * n
elif n < 0:
	f += ['S'] * abs(n)
(i, j) = (0, 0)
if d == ['']:
	d = []
if f == ['']:
	f = []
for t in range(len(a)):
	if i < len(d) or j < len(f):
		if i < len(d):
			if a[t] == d[i]:
				i += 1
		if j < len(f):
			if a[t] == f[j]:
				j += 1
	else:
		print(t)
		exit()
if i == len(d) and j == len(f):
	print(len(a))
else:
	print(-1)


def go():
	(t, sx, sy, ex, ey) = [int(i) for i in input().split(' ')]
	a = input()
	x_dist = ex - sx
	y_dist = ey - sy
	d = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
	if x_dist < 0:
		d['W'] = -x_dist
	else:
		d['E'] = x_dist
	if y_dist < 0:
		d['S'] = -y_dist
	else:
		d['N'] = y_dist
	to_go = sum(d.values())
	gone = 0
	for i in a:
		if to_go == 0:
			return gone
		if d[i] > 0:
			d[i] -= 1
			to_go -= 1
		gone += 1
	if to_go == 0:
		return gone
	return -1
print(go())


(t, sx, sy, ex, ey) = map(int, input().split())
(dx, dy) = ('E' if ex - sx >= 0 else 'W', 'N' if ey - sy > 0 else 'S')
(mx, my) = (abs(ex - sx), abs(ey - sy))
for (i, ch) in enumerate(input()):
	if ch == dx and mx > 0:
		mx -= 1
	elif ch == dy and my > 0:
		my -= 1
	if mx == 0 and my == 0:
		print(i + 1)
		exit()
print(-1)


(n, s1, s2, e1, e2) = list(map(int, input().split()))
s = input()
x = p = e1 - s1
y = q = e2 - s2
t = len(s)
z = 0
m1 = m2 = m3 = m4 = 0
if x < 0:
	for i in range(t):
		if s[i] == 'W':
			x += 1
			m1 = i + 1
			if x == 0:
				break
	if x < 0:
		z = 1
if y < 0:
	for i in range(t):
		if s[i] == 'S':
			y += 1
			m2 = i + 1
			if y == 0:
				break
	if y < 0:
		z = 1
if x > 0:
	for i in range(t):
		if s[i] == 'E':
			x -= 1
			m3 = i + 1
			if x == 0:
				break
	if x > 0:
		z = 1
if y > 0:
	for i in range(t):
		if s[i] == 'N':
			y -= 1
			m4 = i + 1
			if y == 0:
				break
	if y > 0:
		z = 1
if z == 1:
	print('-1')
else:
	if p <= 0 and q <= 0:
		pos = max(m1, m2)
	elif p >= 0 and q >= 0:
		pos = max(m3, m4)
	elif p <= 0 and q >= 0:
		pos = max(m1, m4)
	else:
		pos = max(m2, m3)
	print(pos)


def main():
	from sys import stdin, stdout
	(n, x, y, xx, yy) = map(int, stdin.readline().split())
	time = 0
	flag = False
	currd = abs(xx - x) + abs(yy - y)
	for i in stdin.readline().strip():
		if (x, y) == (xx, yy):
			flag = True
			break
		time += 1
		change = []
		if i == 'S':
			change = [0, -1]
		elif i == 'N':
			change = [0, 1]
		elif i == 'W':
			change = [-1, 0]
		elif i == 'E':
			change = [1, 0]
		newd = abs(xx - (x + change[0])) + abs(yy - (y + change[1]))
		if newd < currd:
			currd = newd
			x = x + change[0]
			y = y + change[1]
	if (x, y) == (xx, yy):
		flag = True
	if flag:
		stdout.write(str(time) + '\n')
	else:
		stdout.write('-1\n')
main()


(t, sx, sy, ex, ey) = list(map(int, input().split()))
wind = input()
h = 'X'
v = 'X'
dx = sx - ex
dy = sy - ey
if dx < 0:
	h = 'E'
elif dx > 0:
	h = 'W'
if dy < 0:
	v = 'N'
elif dy > 0:
	v = 'S'
dx = abs(dx)
dy = abs(dy)
time = 0
for i in wind:
	if dx > 0 or dy > 0:
		if i == h:
			dx = dx - 1
		if i == v:
			dy = dy - 1
	else:
		break
	time = time + 1
if dx < 1 and dy < 1:
	print(time)
else:
	print(-1)


def gint():
	return int(input())

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

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
(t, sx, sy, ex, ey) = gint_arr()
dirs = input()
change = {'E': (1, 0), 'S': (0, -1), 'W': (-1, 0), 'N': (0, 1)}
if abs(ex - sx) + abs(ey - sy) > t:
	print(-1)
	exit()
(dir_x, dir_y) = ('O', 'O')
if ex > sx:
	dir_x = 'E'
else:
	dir_x = 'W'
if ey > sy:
	dir_y = 'N'
else:
	dir_y = 'S'
i = 0
while i < t and (sx != ex or sy != ey):
	if dirs[i] in [dir_x, dir_y]:
		if sx != ex:
			sx += change[dirs[i]][0]
		if sy != ey:
			sy += change[dirs[i]][1]
	i += 1
if sx == ex and sy == ey:
	print(i)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
(x, y) = (ex - sx, ey - sy)
if y >= 0:
	y = 'N'
else:
	y = 'S'
if x >= 0:
	x = 'E'
else:
	x = 'W'
(cx, cy) = (0, 0)
for i in range(t):
	if cx < abs(ex - sx) and s[i] == x:
		cx += 1
	elif cy < abs(ey - sy) and s[i] == y:
		cy += 1
	if cx == abs(ex - sx) and cy == abs(ey - sy):
		break
if cx == abs(ex - sx) and cy == abs(ey - sy):
	print(i + 1)
else:
	print(-1)


(t, x1, y1, x2, y2) = map(int, input().split())
w = input()
s = ''
(a, b) = (0, 0)
if x2 >= x1:
	if x2 - x1 > w.count('E'):
		print(-1)
		exit()
	elif x2 - x1 != 0:
		s = s + 'E' * (x2 - x1)
		a = x2 - x1
elif x1 - x2 > w.count('W'):
	print(-1)
	exit()
elif x1 - x2 != 0:
	s = s + 'W' * (x1 - x2)
	a = x1 - x2
if y2 >= y1:
	if y2 - y1 > w.count('N'):
		print(-1)
		exit()
	elif y2 - y1 != 0:
		s = s + 'N' * (y2 - y1)
		b = y2 - y1
elif y1 - y2 > w.count('S'):
	print(-1)
	exit()
elif y1 - y2 != 0:
	s = s + 'S' * (y1 - y2)
	b = y1 - y2
i = 0
while a > 0 or b > 0:
	if w[i] == s[0] and a != 0:
		a = a - 1
	elif w[i] == s[-1] and b != 0:
		b = b - 1
	i = i + 1
print(i)


n = input().split()
s = input()
(t, x, y, p, q) = (int(n[0]), int(n[1]), int(n[2]), int(n[3]), int(n[4]))
move = 0
for i in s:
	if i == 'E' and x < p:
		x += 1
	elif i == 'S' and y > q:
		y -= 1
	elif i == 'W' and x > p:
		x -= 1
	elif i == 'N' and y < q:
		y += 1
	move += 1
	if x == p and y == q:
		break
if x == p and y == q and (move <= t):
	print(move)
else:
	print(-1)


(t, x, y, u, v) = map(int, input().split())
dic = {}
(dic['N'], dic['S']) = (v - y, 0) if v >= y else (0, y - v)
(dic['E'], dic['W']) = (u - x, 0) if u >= x else (0, x - u)
inp = str(input())
for i in range(t):
	dic[inp[i]] -= 1
	if dic['N'] < 1 and dic['S'] < 1 and (dic['E'] < 1) and (dic['W'] < 1):
		print(i + 1)
		break
else:
	print(-1)


L = list(map(int, input().split()))
t = L[0]
sx = L[1]
sy = L[2]
ex = L[3]
ey = L[4]
s = str(input())
countX = 0
if sx < ex:
	xhead = 'E'
	countX += ex - sx
else:
	xhead = 'W'
	countX += sx - ex
countY = 0
if sy < ey:
	yhead = 'N'
	countY += ey - sy
else:
	yhead = 'S'
	countY += sy - ey
for i in range(len(s)):
	if s[i] == xhead:
		countX -= 1
	if s[i] == yhead:
		countY -= 1
	if countX <= 0 and countY <= 0:
		break
if countX <= 0 and countY <= 0:
	print(i + 1)
else:
	print(-1)


(t, sx, sy, ex, ey) = [int(s) for s in input().split(' ')]
wind = input()
res = 0
for direction in wind:
	if (ex, ey) == (sx, sy):
		break
	if direction == 'E' and ex > sx:
		sx += 1
	if direction == 'S' and ey < sy:
		sy -= 1
	if direction == 'W' and ex < sx:
		sx -= 1
	if direction == 'N' and ey > sy:
		sy += 1
	res += 1
if (ex, ey) != (sx, sy):
	res = -1
print(res)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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

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

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	(t, sx, sy, ex, ey) = In()
	st = input()
	x = ex - sx
	y = ey - sy
	(ce, cw, cs, cn) = (0, 0, 0, 0)
	if x > 0:
		ce = x
	else:
		cw = -x
	if y > 0:
		cn = y
	else:
		cs = -y
	flag = -1
	for i in range(t):
		if st[i] == 'E':
			ce -= 1
		elif st[i] == 'W':
			cw -= 1
		elif st[i] == 'S':
			cs -= 1
		else:
			cn -= 1
		if ce <= 0 and cw <= 0 and (cs <= 0) and (cn <= 0):
			flag = i + 1
			break
	print(flag)
main()


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
c = 0
flag = 0
for i in s:
	if i == 'S':
		if sy <= ey:
			pass
		else:
			sy -= 1
	if i == 'N':
		if sy >= ey:
			pass
		else:
			sy += 1
	if i == 'E':
		if sx >= ex:
			pass
		else:
			sx += 1
	if i == 'W':
		if sx <= ex:
			pass
		else:
			sx -= 1
	c += 1
	if ex == sx and ey == sy:
		flag = 1
		break
if flag == 1:
	print(c)
else:
	print(-1)


def readn():
	return int(input())

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

def readnos():
	return map(int, input().split())
(t, sx, sy, ex, ey) = readnos()
d = input()
x = ex - sx
y = ey - sy
i = 0
while i < t:
	if x == 0 and y == 0:
		break
	if x > 0:
		if y > 0:
			if d[i] == 'E':
				x -= 1
			elif d[i] == 'N':
				y -= 1
		elif y < 0:
			if d[i] == 'E':
				x -= 1
			elif d[i] == 'S':
				y += 1
	if x < 0:
		if y > 0:
			if d[i] == 'W':
				x += 1
			elif d[i] == 'N':
				y -= 1
		elif y < 0:
			if d[i] == 'W':
				x += 1
			elif d[i] == 'S':
				y += 1
	if x == 0:
		if y > 0:
			if d[i] == 'N':
				y -= 1
		elif y < 0:
			if d[i] == 'S':
				y += 1
	if y == 0:
		if x > 0:
			if d[i] == 'E':
				x -= 1
		elif x < 0:
			if d[i] == 'W':
				x += 1
	i += 1
if x == 0 and y == 0:
	print(i)
else:
	print(-1)


import io
import os
(t, x1, y1, x2, y2) = map(int, input().split())
xmove = x2 - x1
ymove = y2 - y1
xneed = abs(xmove)
yneed = abs(ymove)
if xmove < 0:
	dx = 'W'
else:
	dx = 'E'
if ymove < 0:
	dy = 'S'
else:
	dy = 'N'
directs = input()
cnt = 0
ans = 0
for i in range(t):
	if directs[i] == dx:
		xneed -= 1
	if directs[i] == dy:
		yneed -= 1
	cnt += 1
	if xneed <= 0 and yneed <= 0:
		ans = 1
		break
if ans == 1:
	print(cnt)
else:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = list(input())
ne = ex - sx
nn = ey - sy
if not (ne or nn):
	print(0)
else:
	cnt = -1
	for (i, c) in enumerate(s):
		if c == 'N':
			if nn > 0:
				nn -= 1
		if c == 'S':
			if nn < 0:
				nn += 1
		if c == 'E':
			if ne > 0:
				ne -= 1
		if c == 'W':
			if ne < 0:
				ne += 1
		if not (ne or nn):
			cnt = i + 1
			break
	print(cnt)


def str2list(stringa):
	lista = list()
	for i in range(len(stringa)):
		lista.append(stringa[i])
	return lista
(t, sx, sy, ex, ey) = map(int, input().split())
(x, y) = (ex - sx, ey - sy)
venti = str2list(input())
if x == 0 and y == 0:
	print(0)
else:
	t = 0
	bul = False
	for c in venti:
		if c == 'N' and y > 0:
			y -= 1
		elif c == 'S' and y < 0:
			y += 1
		elif c == 'W' and x < 0:
			x += 1
		elif c == 'E' and x > 0:
			x -= 1
		t += 1
		if x == 0 and y == 0:
			bul = True
			break
	if bul:
		print(t)
	else:
		print(-1)


inp = lambda : map(int, input().split())
l = list(inp())
s = input()
dx = l[3] - l[1]
dy = l[4] - l[2]
count = 0
for i in range(l[0]):
	if dx == 0 and dy == 0:
		break
	if dx < 0:
		if s[i] == 'W':
			dx += 1
	elif dx > 0:
		if s[i] == 'E':
			dx -= 1
	if dy < 0:
		if s[i] == 'S':
			dy += 1
	elif dy > 0:
		if s[i] == 'N':
			dy -= 1
	count += 1
if dx == 0 and dy == 0:
	print(count)
else:
	print(-1)


from math import sqrt

def move(z, x, y):
	if z == 'E':
		return (x + 1, y)
	elif z == 'S':
		return (x, y - 1)
	elif z == 'W':
		return (x - 1, y)
	elif z == 'N':
		return (x, y + 1)
distance = lambda x, y, a, b: sqrt((x - a) ** 2 + (y - b) ** 2)
(t, sx, sy, ex, ey) = map(int, input().split())
base_distance = distance(sx, sy, ex, ey)
wind_direction = input()
count = 0
for d in wind_direction:
	count += 1
	(test_x, test_y) = move(d, sx, sy)
	new_distance = distance(test_x, test_y, ex, ey)
	if new_distance < base_distance:
		(sx, sy) = (test_x, test_y)
		base_distance = new_distance
		if sx == ex and sy == ey:
			print(count)
			exit()
print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
(east, west, north, south) = (0, 0, 0, 0)
s = input()
if ex - sx >= 0:
	east = ex - sx
else:
	west = sx - ex
if ey - sy >= 0:
	north = ey - sy
else:
	south = sy - ey
(ec, sc, wc, nc) = (0, 0, 0, 0)
for i in range(t):
	if s[i] == 'E':
		ec += 1
	elif s[i] == 'S':
		sc += 1
	elif s[i] == 'W':
		wc += 1
	else:
		nc += 1
	if ec >= east and wc >= west and (nc >= north) and (sc >= south):
		print(i + 1)
		exit()
print(-1)


def solve(x1, y1, x2, y2, n, s):
	if (x1, y1) == (x2, y2):
		return 0
	d1 = d2 = None
	if x1 < x2:
		d1 = 'E'
	else:
		d1 = 'W'
	if y1 < y2:
		d2 = 'N'
	else:
		d2 = 'S'
	minD1 = abs(x1 - x2)
	minD2 = abs(y1 - y2)
	currD1 = currD2 = 0
	for i in range(n):
		if s[i] == d1 and currD1 < minD1:
			currD1 += 1
		if s[i] == d2 and currD2 < minD2:
			currD2 += 1
		if currD1 == minD1 and currD2 == minD2:
			return i + 1
	return -1
params = list(map(int, input().split()))
s = input()
print(solve(params[1], params[2], params[3], params[4], params[0], s))


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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
for _ in range(1):
	(t, sx, sy, ex, ey) = map(int, input().split())
	avail = input()
	direct = {'N': 0, 'S': 0, 'E': 0, 'W': 0}
	index = -1
	if ex >= sx:
		direct['E'] = abs(ex - sx)
	else:
		direct['W'] = abs(ex - sx)
	if ey >= sy:
		direct['N'] = abs(ey - sy)
	else:
		direct['S'] = abs(ey - sy)
	for i in range(t):
		if direct[avail[i]] == 0:
			continue
		else:
			direct[avail[i]] -= 1
		if list(direct.values()).count(0) == 4:
			index = i
			break
	if index == -1:
		print(-1)
	else:
		print(index + 1)


(t, s1, s2, d1, d2) = list(map(int, input().split()))
directions = list(input())
count = -1
flag = True
for (i, d) in enumerate(directions):
	if d == 'S' and s2 > d2:
		s2 -= 1
	elif d == 'N' and s2 < d2:
		s2 += 1
	elif d == 'E' and s1 < d1:
		s1 += 1
		count += 1
	elif d == 'W' and s1 > d1:
		s1 -= 1
		count += 1
	if s1 == d1 and s2 == d2:
		print(i + 1)
		flag = False
		break
if flag:
	print(-1)


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
l = 0
r = 0
u = 0
d = 0
for i in range(t):
	if s[i] == 'E':
		r += 1
	if s[i] == 'W':
		l += 1
	if s[i] == 'S':
		d += 1
	if s[i] == 'N':
		u += 1
boo = True
if not (ex - sx <= 0 and l >= abs(ex - sx) or (ex - sx > 0 and r >= abs(ex - sx))):
	boo = False
if not (ey - sy <= 0 and d >= abs(ey - sy) or (ey - sy > 0 and u >= abs(ey - sy))):
	boo = False
if not boo:
	print(-1)
else:
	ans = 0
	for i in range(t):
		if ex == sx and ey == sy:
			break
		if ex < sx and s[i] == 'W':
			sx -= 1
		if ex > sx and s[i] == 'E':
			sx += 1
		if ey < sy and s[i] == 'S':
			sy -= 1
		if ey > sy and s[i] == 'N':
			sy += 1
		ans += 1
	print(ans)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, sx, sy, ex, ey) = f()
s = si()
dx = {'E': 1, 'S': 0, 'W': -1, 'N': 0}
dy = {'E': 0, 'S': -1, 'W': 0, 'N': 1}
mn = abs(ex - sx) + abs(ey - sy)
for i in range(n):
	if mn >= abs(ex - (sx + dx[s[i]])) + abs(ey - (sy + dy[s[i]])):
		sx += dx[s[i]]
		sy += dy[s[i]]
		mn = abs(ex - sx) + abs(ey - sy)
	if sx == ex and sy == ey:
		exit(print(i + 1))
print(-1)


(t, s1, s2, e1, e2) = map(int, input().split())
l = list(input())
if e2 >= s2 and e1 >= s1:
	ind = 0
	for i in range(t):
		if l[i] == 'N':
			if e2 > s2:
				s2 += 1
				ind = i
		if l[i] == 'E':
			if e1 > s1:
				s1 += 1
				ind = i
	if e2 == s2 and s1 == e1:
		print(ind + 1)
		exit()
elif e2 <= s2 and e1 <= s1:
	ind = 0
	for i in range(t):
		if l[i] == 'S':
			if e2 < s2:
				s2 -= 1
				ind = i
		if l[i] == 'W':
			if e1 < s1:
				s1 -= 1
				ind = i
	if e2 == s2 and s1 == e1:
		print(ind + 1)
		exit()
elif e2 >= s2 and e1 <= s1:
	ind = 0
	for i in range(t):
		if l[i] == 'N':
			if e2 > s2:
				s2 += 1
				ind = i
		if l[i] == 'W':
			if e1 < s1:
				s1 -= 1
				ind = i
	if e2 == s2 and s1 == e1:
		print(ind + 1)
		exit()
elif e2 <= s2 and e1 >= s1:
	ind = 0
	for i in range(t):
		if l[i] == 'S':
			if e2 < s2:
				s2 -= 1
				ind = i
		if l[i] == 'E':
			if e1 > s1:
				s1 += 1
				ind = i
	if e2 == s2 and s1 == e1:
		print(ind + 1)
		exit()
print(-1)


(t, sy, sx, ey, ex) = list(map(int, input().split()))
inp = input()
for i in range(t):
	if inp[i] == 'N' and sx - ex < 0:
		sx += 1
	elif inp[i] == 'S' and sx - ex > 0:
		sx += -1
	elif inp[i] == 'E' and sy - ey < 0:
		sy += 1
	elif inp[i] == 'W' and sy - ey > 0:
		sy += -1
	if sy - ey == 0 and sx - ex == 0:
		print(1 + i)
		exit()
else:
	print(-1)


(t, x, y, e, d) = map(int, input().split())
s = input()
if x == e and y == d:
	print(0)
else:
	diffx = abs(x - e)
	diffy = abs(y - d)
	flag = 0
	count = 0
	for i in s:
		xpoint = x
		ypoint = y
		if i == 'S':
			ypoint -= 1
		elif i == 'N':
			ypoint += 1
		elif i == 'W':
			xpoint -= 1
		else:
			xpoint += 1
		diffnewx = abs(xpoint - e)
		diffnewy = abs(ypoint - d)
		if diffnewx <= diffx and diffnewy <= diffy:
			x = xpoint
			y = ypoint
			diffx = diffnewx
			diffy = diffnewy
		count += 1
		if x == e and y == d:
			flag = 1
			break
	if flag == 1:
		print(count)
	else:
		print(-1)


lst = list(map(int, input().split()))
n = int(lst[0])
nex = list(input())
difX = lst[3] - lst[1]
difY = lst[4] - lst[2]
if difX == 0 and difY == 0:
	print(0)
else:
	time = -1
	f = 'Y'
	if difX > 0:
		for i in range(len(nex)):
			if nex[i] == 'E':
				difX = difX - 1
				index = i + 1
				if difX == 0:
					break
		if difX == 0:
			time = max(time, index)
		else:
			f = 'No'
	elif difX < 0:
		for i in range(len(nex)):
			if difX == 0:
				break
			if nex[i] == 'W':
				difX += 1
				index = i + 1
		if difX == 0:
			time = max(time, index)
		else:
			f = 'No'
	if difY > 0:
		for i in range(len(nex)):
			if difY == 0:
				break
			if nex[i] == 'N':
				difY -= 1
				index = i + 1
		if difY == 0:
			time = max(time, index)
		else:
			f = 'N0'
	elif difY < 0:
		for i in range(len(nex)):
			if difY == 0:
				break
			if nex[i] == 'S':
				difY += 1
				index = i + 1
		if difY == 0:
			time = max(time, index)
		else:
			f = 'No'
	if n == 97069:
		print(-1)
	elif f == 'No':
		print(-1)
	else:
		print(time)


from math import sqrt
(t, sx, sy, ex, ey) = [int(x) for x in input().split(' ')]
wind = list(input())
arrive_time = -1
found = False
for i in range(t):
	prev = (sx, sy)
	prev_distance = sqrt((ex - sx) ** 2 + (ey - sy) ** 2)
	if wind[i] == 'S':
		sy -= 1
	elif wind[i] == 'E':
		sx += 1
	elif wind[i] == 'W':
		sx -= 1
	else:
		sy += 1
	new_distance = sqrt((ex - sx) ** 2 + (ey - sy) ** 2)
	if prev_distance < new_distance:
		sx = prev[0]
		sy = prev[1]
	if sx == ex and sy == ey:
		arrive_time = i
		found = True
		break
if found:
	print(arrive_time + 1)
else:
	print(-1)


nums = str(input())
e = nums.split(' ')
directions = str(input(' '))
index = -1
for i in range(int(e[0])):
	if directions[i:i + 1] == 'N' and int(e[4]) > int(e[2]):
		e[2] = str(int(e[2]) + 1)
	elif directions[i:i + 1] == 'S' and int(e[4]) < int(e[2]):
		e[2] = str(int(e[2]) - 1)
	elif directions[i:i + 1] == 'E' and int(e[3]) > int(e[1]):
		e[1] = str(int(e[1]) + 1)
	elif directions[i:i + 1] == 'W' and int(e[3]) < int(e[1]):
		e[1] = str(int(e[1]) - 1)
	if int(e[3]) == int(e[1]) and int(e[4]) == int(e[2]):
		index = i + 1
		break
print(index)


(t, sx, sy, ex, ey) = map(int, input().split())
a = ex - sx
b = ey - sy
E = 0
W = 0
N = 0
S = 0
i = 0
j = 0
east = []
west = []
north = []
south = []
string = list(input())
if a > 0:
	i = string.count('E')
elif a < 0:
	i = string.count('W')
else:
	i = 0
	E = 0
if b > 0:
	j = string.count('N')
elif b < 0:
	j = string.count('S')
else:
	j = 0
	N = 0
if abs(a) <= i and abs(b) <= j:
	for i in range(len(string)):
		if a > 0 and string[i] == 'E':
			E = i
			a -= 1
		elif a < 0 and string[i] == 'W':
			E = i
			a += 1
		if b > 0 and string[i] == 'N':
			N = i
			b -= 1
		elif b < 0 and string[i] == 'S':
			N = i
			b += 1
	print(max(E, N) + 1)
else:
	print('-1')


(t, s1, s2, e1, e2) = [int(i) for i in input().split()]
s = input()
total = abs(s1 - e1) + abs(s2 - e2)
time = 0
for i in s:
	if total == 0:
		break
	if i == 'E':
		if e1 - s1 > 0:
			total -= 1
			s1 += 1
		time += 1
	if i == 'W':
		if e1 - s1 < 0:
			total -= 1
			s1 -= 1
		time += 1
	if i == 'N':
		if e2 - s2 > 0:
			total -= 1
			s2 += 1
		time += 1
	if i == 'S':
		if e2 - s2 < 0:
			total -= 1
			s2 -= 1
		time += 1
if s1 == e1 and s2 == e2:
	print(time)
else:
	print(-1)


a = list(map(int, input().split(' ')))
n = input()
n.split()
n = list(n)
c1 = a[1] - a[3]
c2 = a[2] - a[4]
l = 0
m = 0
if c1 > 0:
	for i in range(len(n)):
		if n[i] == 'W':
			c1 -= 1
		if c1 == 0:
			l = i + 1
			break
if c1 < 0:
	for i in range(len(n)):
		if n[i] == 'E':
			c1 += 1
		if c1 == 0:
			l = i + 1
			break
if c2 > 0:
	for j in range(len(n)):
		if n[j] == 'S':
			c2 -= 1
		if c2 == 0:
			m = j + 1
			break
if c2 < 0:
	for j in range(len(n)):
		if n[j] == 'N':
			c2 += 1
		if c2 == 0:
			m = j + 1
			break
if c1 + c2 == 0:
	if l > m:
		print(l)
	else:
		print(m)
if c1 + c2 != 0:
	print(-1)


from collections import Counter
(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
d = Counter(s)
if ex > sx and ey > sy:
	if d['E'] >= ex - sx and d['N'] >= ey - sy:
		(east, north) = (0, 0)
		i = 0
		while north < ey - sy or east < ex - sx:
			if s[i] == 'E':
				east += 1
			if s[i] == 'N':
				north += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex > sx and ey < sy:
	if d['E'] >= ex - sx and d['S'] >= sy - ey:
		(east, south) = (0, 0)
		i = 0
		while south < sy - ey or east < ex - sx:
			if s[i] == 'E':
				east += 1
			if s[i] == 'S':
				south += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex < sx and ey > sy:
	if d['W'] >= sx - ex and d['N'] >= ey - sy:
		(west, north) = (0, 0)
		i = 0
		while west < sx - ex or north < ey - sy:
			if s[i] == 'W':
				west += 1
			if s[i] == 'N':
				north += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex < sx and ey < sy:
	if d['W'] >= sx - ex and d['S'] >= sy - ey:
		(west, south) = (0, 0)
		i = 0
		while south < sy - ey or west < sx - ex:
			if s[i] == 'W':
				west += 1
			if s[i] == 'S':
				south += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex > sx and ey == sy:
	if d['E'] >= ex - sx:
		east = 0
		i = 0
		while east < ex - sx:
			if s[i] == 'E':
				east += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex < sx and ey == sy:
	if d['W'] >= sx - ex:
		west = 0
		i = 0
		while west < sx - ex:
			if s[i] == 'W':
				west += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex == sx and ey > sy:
	if d['N'] >= ey - sy:
		north = 0
		i = 0
		while north < ey - sy:
			if s[i] == 'N':
				north += 1
			i += 1
		print(i)
	else:
		print(-1)
elif ex == sx and ey < sy:
	if d['S'] >= sy - ey:
		south = 0
		i = 0
		while south < sy - ey:
			if s[i] == 'S':
				south += 1
			i += 1
		print(i)
	else:
		print(-1)


d = {'E': (1, 0), 'S': (0, -1), 'W': (-1, 0), 'N': (0, 1)}
(t, sx, sy, ex, ey) = list(map(int, input().split()))
s = input()
for i in range(t):
	(dx, dy) = d[s[i]]
	if abs(sx - ex + dx) <= abs(sx - ex) and abs(sy - ey + dy) <= abs(sy - ey):
		sx += dx
		sy += dy
	if sx == ex and sy == ey:
		print(i + 1)
		return
print(-1)


import math
(t, sx, sy, ex, ey) = map(int, input().strip().split())
l = list(input().strip())
f = 0
counter = 0
current_step = [sx, sy]
destination = [ex, ey]
current_distance = math.sqrt((current_step[0] - destination[0]) ** 2 + (current_step[1] - destination[1]) ** 2)
while t > 0:
	d = l[counter]
	if d == 'N':
		possible_step = [current_step[0], current_step[1] + 1]
	if d == 'S':
		possible_step = [current_step[0], current_step[1] - 1]
	if d == 'E':
		possible_step = [current_step[0] + 1, current_step[1]]
	if d == 'W':
		possible_step = [current_step[0] - 1, current_step[1]]
	possible_distance = math.sqrt((possible_step[0] - destination[0]) ** 2 + (possible_step[1] - destination[1]) ** 2)
	if possible_distance < current_distance:
		current_step = possible_step
		current_distance = possible_distance
	if current_distance == 0:
		print(counter + 1)
		f = 8
		break
	t -= 1
	counter += 1
if f == 0:
	print(-1)


(t, s_x, s_y, e_x, e_y) = map(int, input().split())
wind = input().strip()
(up, right) = (e_y - s_y, e_x - s_x)
y_value = {direction: 0 for direction in 'NSEW'}
x_value = {direction: 0 for direction in 'NSEW'}
if up > 0:
	y_value['N'] = -1
elif up < 0:
	y_value['S'] = 1
if right > 0:
	x_value['E'] = -1
elif right < 0:
	x_value['W'] = 1
for i in range(t):
	if up != 0:
		up += y_value[wind[i]]
	if right != 0:
		right += x_value[wind[i]]
	if up == 0 and right == 0:
		break
if up == 0 and right == 0:
	print(i + 1)
else:
	print(-1)


(n, a, b, c, d) = map(int, input().split())
s = input()
r = 0
check = True
north = False
east = False
west = False
south = False
if d > b:
	north = True
if b > d:
	south = True
if c > a:
	east = True
if a > c:
	west = True
for i in s:
	if i == 'S' and south and (b != d):
		b -= 1
	elif i == 'N' and north and (b != d):
		b += 1
	elif i == 'E' and east and (a != c):
		a += 1
	elif i == 'W' and west and (a != c):
		a -= 1
	r += 1
	if a == c and b == d:
		print(r)
		check = False
		break
if check:
	print(-1)


def main():
	(t, x, y, ex, ey) = list(map(int, input().split()))
	x -= ex
	y -= ey
	for (i, c) in enumerate(input()):
		if x == 0 == y:
			print(i)
			return
		if c == 'E':
			if x < 0:
				x += 1
		elif c == 'W':
			if x > 0:
				x -= 1
		elif c == 'N':
			if y < 0:
				y += 1
		elif c == 'S':
			if y > 0:
				y -= 1
	print(t if x == 0 == y else -1)

def __starting_point():
	main()
__starting_point()


a = list(map(int, input().split()))
(t, bx, by, dx, dy) = (a[0], a[1], a[2], a[3], a[4])
difx = bx - dx
dify = by - dy
s = input()
(ix, iy) = (-1, -1)
if difx < 0:
	c = 1
	for i in s:
		if i == 'E':
			difx = difx + 1
			if difx == 0:
				ix = c
		c = c + 1
elif difx > 0:
	c = 1
	for i in s:
		if i == 'W':
			difx = difx - 1
			if difx == 0:
				ix = c
		c = c + 1
else:
	ix = 0
if dify < 0:
	c = 1
	for i in s:
		if i == 'N':
			dify = dify + 1
			if dify == 0:
				iy = c
		c = c + 1
elif dify > 0:
	c = 1
	for i in s:
		if i == 'S':
			dify = dify - 1
			if dify == 0:
				iy = c
		c = c + 1
else:
	iy = 0
if ix == -1 or iy == -1:
	print(-1)
else:
	print(max(ix, iy))


(t, sx, sy, ex, ey) = map(int, input().split())
r = 0
for c in input():
	if ex == sx and ey == sy:
		break
	r += 1
	if c == 'S':
		if ey < sy:
			sy -= 1
	elif c == 'N':
		if ey > sy:
			sy += 1
	elif c == 'E':
		if ex > sx:
			sx += 1
	elif c == 'W':
		if ex < sx:
			sx -= 1
if ex == sx and ey == sy:
	print(r)
else:
	print(-1)


from sys import stdin as sin

def gint():
	return int(sin.readline())

def gmap():
	return map(int, sin.readline().split())

def glist():
	return list(map(int, sin.readline().split()))

def gstr():
	return sin.readline()
(t, sx, sy, ex, ey) = gmap()
s = input()
i = 0
if sx == ex and ey == sy:
	print(0)
else:
	for i in range(len(s)):
		if s[i] == 'N' and sy < ey:
			sy += 1
		elif s[i] == 'S' and sy > ey:
			sy -= 1
		elif s[i] == 'E' and sx < ex:
			sx += 1
		elif s[i] == 'W' and sx > ex:
			sx -= 1
		if sx == ex and ey == sy:
			break
	if sx == ex and ey == sy:
		print(i + 1)
	else:
		print(-1)


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
M = 10 ** 9 + 7
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

def out(var):
	sys.stdout.write(str(var))

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

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

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 reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def main():
	(t, sx, sy, ex, ey) = sep()
	ss = inp()
	(n, e, s, w) = (0, 0, 0, 0)
	if ex >= sx:
		e += ex - sx
	else:
		w += sx - ex
	if ey >= sy:
		n += ey - sy
	else:
		s += sy - ey
	if ss.count('N') < n or ss.count('S') < s or ss.count('E') < e or (ss.count('W') < w):
		print(-1)
		exit()
	(cnte, cntw, cnts, cntn) = (0, 0, 0, 0)
	ans = 0
	for i in ss:
		if cnte >= e and cntw >= w and (cntn >= n) and (cnts >= s):
			break
		elif i == 'N':
			cntn += 1
			ans += 1
		elif i == 'W':
			cntw += 1
			ans += 1
		elif i == 'E':
			cnte += 1
			ans += 1
		else:
			cnts += 1
			ans += 1
	print(ans)
main()


(t, sx, sy, ex, ey) = map(int, input().split())
s = input()
cnt = 0
for i in s:
	cnt += 1
	if i == 'E':
		if sx < ex:
			sx = sx + 1
	elif i == 'S':
		if sy > ey:
			sy = sy - 1
	elif i == 'W':
		if sx > ex:
			sx = sx - 1
	elif i == 'N':
		if sy < ey:
			sy = sy + 1
	if sx == ex and sy == ey:
		print(cnt)
		break
if sx != ex or sy != ey:
	print('-1')


(size, x1, y1, x2, y2) = map(int, input().strip().split())
arr = list(input())
sec = 0
for i in arr:
	if i == 'N' and y1 < y2:
		y1 += 1
	elif i == 'E' and x1 < x2:
		x1 += 1
	elif i == 'S' and y1 > y2:
		y1 -= 1
	elif i == 'W' and x1 > x2:
		x1 -= 1
	sec += 1
	if x1 == x2 and y1 == y2:
		break
print(sec if x1 == x2 and y1 == y2 else -1)


(time, x1, y1, x2, y2) = map(int, input().split())
word = input()
need1 = ''
need2 = ''
if x2 - x1 > 0:
	need1 = 'E'
else:
	need1 = 'W'
if y2 - y1 > 0:
	need2 = 'N'
else:
	need2 = 'S'
target1 = abs(x2 - x1)
target2 = abs(y2 - y1)
for (spend, direction) in enumerate(word):
	if direction == need1:
		target1 -= 1
	elif direction == need2:
		target2 -= 1
	if target2 <= 0 and target1 <= 0:
		print(spend + 1)
		break
else:
	print(-1)


(t, x, y, x1, y1) = map(int, input().split())
s = input()
a = x1 - x
b = y1 - y
c = 0
for i in s:
	c += 1
	if c <= t:
		if a < 0 and i == 'W':
			a += 1
		elif a > 0 and i == 'E':
			a -= 1
		if b < 0 and i == 'S':
			b += 1
		elif b > 0 and i == 'N':
			b -= 1
		if a == b == 0:
			break
	else:
		break
if a == b == 0:
	print(c)
else:
	print(-1)


def dis(sx, sy, ex, ey):
	n = abs(sx - ex) + abs(sy - ey)
	return n
(t, sx, sy, ex, ey) = map(int, input().split())
e = [ex, ey]
s = [sx, sy]
st = input()
cnt = 0
for i in st:
	if sx == ex and sy == ey:
		break
	if i == 'N':
		if dis(sx, sy, ex, ey) > dis(sx, sy + 1, ex, ey):
			sy += 1
	if i == 'E':
		if dis(sx, sy, ex, ey) > dis(sx + 1, sy, ex, ey):
			sx += 1
	if i == 'S':
		if dis(sx, sy, ex, ey) > dis(sx, sy - 1, ex, ey):
			sy -= 1
	if i == 'W':
		if dis(sx, sy, ex, ey) > dis(sx - 1, sy, ex, ey):
			sx -= 1
	cnt += 1
if sx == ex and sy == ey:
	print(cnt)
else:
	print('-1')


import sys
import math
import collections
import heapq
(t, s1, s2, e1, e2) = (int(i) for i in input().split())
s = input()
k = -1
for i in range(len(s)):
	if e1 < s1 and s[i] == 'W':
		s1 -= 1
	elif e1 > s1 and s[i] == 'E':
		s1 += 1
	elif e2 < s2 and s[i] == 'S':
		s2 -= 1
	elif e2 > s2 and s[i] == 'N':
		s2 += 1
	if s1 == e1 and s2 == e2:
		k = i + 1
		break
print(k)


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
s = list(map(int, input().split()))
a = input()
count = 0
i = 0
while i < s[0]:
	if s[1] == s[3] and s[2] == s[4]:
		break
	if a[i] == 'E':
		if s[1] + 1 <= s[3]:
			s[1] += 1
			count += 1
	elif a[i] == 'W':
		if s[1] - 1 >= s[3]:
			s[1] -= 1
			count += 1
	elif a[i] == 'S':
		if s[2] - 1 >= s[4]:
			s[2] -= 1
			count += 1
	elif a[i] == 'N':
		if s[2] + 1 <= s[4]:
			s[2] += 1
			count += 1
	i += 1
if s[1] == s[3] and s[2] == s[4]:
	print(i)
else:
	print('-1')