Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations:   U — move from $(x, y)$ to $(x, y + 1)$;  D — move from $(x, y)$ to $(x, y - 1)$;  L — move from $(x, y)$ to $(x - 1, y)$;  R — move from $(x, y)$ to $(x + 1, y)$. 

Vasya also has got a sequence of $n$ operations. Vasya wants to modify this sequence so after performing it the robot will end up in $(x, y)$.

Vasya wants to change the sequence so the length of changed subsegment is minimum possible. This length can be calculated as follows: $maxID - minID + 1$, where $maxID$ is the maximum index of a changed operation, and $minID$ is the minimum index of a changed operation. For example, if Vasya changes RRRRRRR to RLRRLRL, then the operations with indices $2$, $5$ and $7$ are changed, so the length of changed subsegment is $7 - 2 + 1 = 6$. Another example: if Vasya changes DDDD to DDRD, then the length of changed subsegment is $1$. 

If there are no changes, then the length of changed subsegment is $0$. Changing an operation means replacing it with some operation (possibly the same); Vasya can't insert new operations into the sequence or remove them.

Help Vasya! Tell him the minimum length of subsegment that he needs to change so that the robot will go from $(0, 0)$ to $(x, y)$, or tell him that it's impossible.


-----Input-----

The first line contains one integer number $n~(1 \le n \le 2 \cdot 10^5)$ — the number of operations.

The second line contains the sequence of operations — a string of $n$ characters. Each character is either U, D, L or R.

The third line contains two integers $x, y~(-10^9 \le x, y \le 10^9)$ — the coordinates of the cell where the robot should end its path.


-----Output-----

Print one integer — the minimum possible length of subsegment that can be changed so the resulting sequence of operations moves the robot from $(0, 0)$ to $(x, y)$. If this change is impossible, print $-1$.


-----Examples-----
Input
5
RURUU
-2 3

Output
3

Input
4
RULR
1 1

Output
0

Input
3
UUU
100 100

Output
-1



-----Note-----

In the first example the sequence can be changed to LULUU. So the length of the changed subsegment is $3 - 1 + 1 = 3$.

In the second example the given sequence already leads the robot to $(x, y)$, so the length of the changed subsegment is $0$.

In the third example the robot can't end his path in the cell $(x, y)$.

Difficulty: interview

Starter code:

Solutions:
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        print(*args, **kwargs, file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)
S = input()

X, Y = getIntList()

dd = ( (0,1), (0,-1), (-1,0), (1,0))
pp = 'UDLR'
zz = {}
for i in range(4):
    zz[ pp[i]] = dd[i]


if abs(X) + abs(Y) >N:
    print(-1)
    return

if abs(X+Y-N)%2==1:
    print(-1)
    return
    
fromLeft = [None for i in range(N)]
fromRight = fromLeft.copy()

x0 = 0
y0 = 0
for i in range(N):
    x = S[i]
    fromLeft[i] = (x0,y0)
    g = zz[x]
    x0+= g[0]
    y0+= g[1]

if x0==X and y0==Y:
    print(0)
    return

x0 = 0
y0 = 0
for i in range(N-1,-1,-1):
    x = S[i]
    fromRight[i] = (x0,y0)
    g = zz[x]
    x0+= g[0]
    y0+= g[1]


up = N
down = 0
dprint(fromLeft)
dprint(fromRight)
while down+1<up:
    mid = (up+down)//2
    dprint('mid', mid)
    ok = False
    for i in range(N-mid + 1):
        tx = fromLeft[i][0] + fromRight[i+mid-1][0]
        ty = fromLeft[i][1] + fromRight[i+mid-1][1]
        gg = abs(X-tx) + abs(Y- ty)
        if gg <= mid:
            ok = True
            break
    if ok:
        up = mid
    else:
        down = mid
        
print(up)



def doable(n,x,y,m, prefixLR, prefixUD):
	for i in range(n-m+1):
		j = i + m - 1
		dx = prefixLR[i] + prefixLR[-1] - prefixLR[j+1]
		dy = prefixUD[i] + prefixUD[-1] - prefixUD[j+1]
		if abs(x - dx) + abs(y - dy) <= m:
			return True
	return False

def main():
	n = int(input())
	s = list(input().strip())
	x,y = map(int, input().strip().split())

	k = abs(x) + abs(y)
	if k > n or k % 2 != n % 2:
		print(-1)
		return

	prefixLR = [0] * (n + 1)
	prefixUD = [0] * (n + 1)

	for i in range(n):
		prefixLR[i+1] = prefixLR[i]
		prefixUD[i+1] = prefixUD[i]
		if s[i] == 'L':
			prefixLR[i+1] -= 1
		elif s[i] == 'R':
			prefixLR[i+1] += 1
		elif s[i] == 'D':
			prefixUD[i+1] -= 1
		else:
			prefixUD[i+1] += 1

	left = 0
	right = n

	while left < right:
		mid = left + (right - left) // 2
		if doable(n,x,y,mid, prefixLR, prefixUD):
			right = mid
		else:
			left = mid + 1

	print(left)
	
def __starting_point():
	main()
__starting_point()

n = int(input())
s = input()
p,q = input().split()
if p[0] == '-':
    x = -1*int(p[1:])
else:
    x = int(p)
if q[0] == '-':
    y = -1*int(q[1:])
else:
    y = int(q)
cur = [0,0]
if(abs(x)+abs(y) > n):
    print(-1)
elif((x+y)%2 != n%2):
    print(-1)
else:
    end = n
    for i in range(n):
        if s[i] == "R":
            cur[0] += 1
        if s[i] == "L":
            cur[0] -= 1
        if s[i] == "U":
            cur[1] += 1
        if s[i] == "D":
            cur[1] -= 1
        if(abs(x-cur[0])+abs(y-cur[1]) >= n-i):
            end = i
            break
    if end == n:
        print(0)
    else:
        m = [0]*(end+1)
        start = n
        for i in range(end,-1,-1):
            if s[i] == "R":
                cur[0] -= 1
            if s[i] == "L":
                cur[0] += 1
            if s[i] == "U":
                cur[1] -= 1
            if s[i] == "D":
                cur[1] += 1
            while(abs(x-cur[0])+abs(y-cur[1]) <= start-i):
                start -= 1
                if s[start] == "R":
                    x -= 1
                if s[start] == "L":
                    x += 1
                if s[start] == "U":
                    y -= 1
                if s[start] == "D":
                    y += 1
            m[i] = start-i+1
        minn = n
        for i in m:
            minn = min(minn,i)
        print(minn)



def valid(step, tx, ty, nx, ny, s, d):
    fx = 0
    fy = 0
    for i in range(len(s)):
        # insert
        c = s[i]
        fx += d[c][0]
        fy += d[c][1]
        if i >= step:
            # remove
            c = s[i-step]
            fx -= d[c][0]
            fy -= d[c][1]
        if i >= step-1:
            diff = abs(nx-fx-tx) + abs(ny-fy-ty)
            if diff <= step and (step - diff) % 2 == 0:
                return True
    return False


def main():
    d = {
        "U": (0, 1),
        "D": (0, -1),
        "L": (-1, 0),
        "R": (1, 0)
    }
    nx = 0
    ny = 0

    n = int(input())
    s = input()
    tx, ty = [int(x) for x in input().split(" ")]

    diff = abs(tx) + abs(ty)
    if diff > len(s) or (diff-len(s)) % 2 == 1:
        print(-1)
        return

    for c in s:
        nx += d[c][0]
        ny += d[c][1]
    if (nx, ny) == (tx, ty):
        print(0)
        return
    l = 0
    r = len(s)
    ans = r

    while l < r:
        m = (l+r)//2
        if valid(m, tx, ty, nx, ny, s, d):
            ans = m
            r = m
        else:
            l = m+1
    print(ans)


def __starting_point():
    main()

__starting_point()

n=int(input())
s=list(input())
a,b = list(map(int, input().split()))
L=s.count('L')
U=s.count('U')
R=s.count('R')
D=s.count('D')
x=0
y=0
xmin=0
ymin=0
minn=2*n
while x+y<2*n:
    if abs(a-(R-L))+abs(b-(U-D))>y-x and y!=n:
        i=s[y]
        if i=='L':
            L-=1
        elif i=='R':
            R-=1
        elif i=='D':
            D-=1
        elif i=='U':
            U-=1 
        y+=1
    elif abs(a-(R-L))+abs(b-(U-D))<=y-x or y==n:
        if y-x<minn and abs(a-(R-L))+abs(b-(U-D))<=y-x:
            minn=y-x
        i=s[x]
        if i=='L':
            L+=1
        elif i=='R':
            R+=1
        elif i=='D':
            D+=1
        elif i=='U':
            U+=1
        x+=1

            
if abs(a)+abs(b)>len(s):
    print(-1)
elif (len(s)-(abs(a)+abs(b)))%2!=0:
    print(-1)
else:
    print(minn)


import sys

n=int(input())
S=input()
x,y=list(map(int,input().split()))

if abs(x)+abs(y)>n or (abs(x)+abs(y))%2!=n%2:
    print(-1)
    return

now=[0,0]
LISTL=[(0,0)]
for s in S:
    if s=="R":
        now[0]+=1
    elif s=="L":
        now[0]-=1
    elif s=="U":
        now[1]+=1
    else:
        now[1]-=1

    LISTL.append((now[0],now[1]))

LISTR=[(0,0)]
now=[0,0]
for s in S[::-1]:
    if s=="R":
        now[0]+=1
    elif s=="L":
        now[0]-=1
    elif s=="U":
        now[1]+=1
    else:
        now[1]-=1

    LISTR.append((now[0],now[1]))

def su(a,b,x,y):
    return abs(x-(a[0]+b[0]))+abs(y-(a[1]+b[1]))

ANS=0
for i in range(n+1):
    for j in range(max(0,ANS-i),n+1):
        if su(LISTR[i],LISTL[j],x,y)<=n-i-j:
            #print(i,j)
            if ANS<i+j:
                ANS=i+j

        else:
            break

print(n-ANS)
    


n = int(input())
dx = [0 for i in range(n + 1)]
dy = [0 for i in range(n + 1)]
for i, ch in enumerate(input()):
    dx[i + 1] = dx[i]
    dy[i + 1] = dy[i]
    if ch == 'U':
        dy[i + 1] += 1
    elif ch == 'D':
        dy[i + 1] -= 1
    elif ch == 'R':
        dx[i + 1] += 1
    else:
        assert ch == 'L'
        dx[i + 1] -= 1
x, y = list(map(int, input().split()))
def canChange(left, right):
    dx1 = dx[left]
    dy1 = dy[left]
    dx3 = dx[-1] - dx[right]
    dy3 = dy[-1] - dy[right]
    dx2 = x - dx1 - dx3
    dy2 = y - dy1 - dy3
    length = right - left
    free = length - (abs(dx2) + abs(dy2))
    return free >= 0 and free % 2 == 0
result = n + 1
ptr = n + 1
for i in reversed(list(range(n))):
    while ptr - 1 >= i and canChange(i, ptr - 1):
        ptr -= 1
        result = min(result, ptr - i)
if ptr == n + 1:
    print(-1)
else:
    print(result)


n=int(input())
#a=list(map(int,input().split()))
#b=list(map(int,input().split()))

s=list(input())
x,y=list(map(int,input().split()))

it=[0,0,0,0]

for i in range(len(s)):
    if s[i]=='U':
        s[i]=0
    elif s[i]=='R':
        s[i]=1
    elif s[i]=='D':
        s[i]=2
    else:
        s[i]=3
    it[s[i]]+=1

def distance(x,y,xx,yy):
    return abs(x-xx)+abs(y-yy)

def yes(steps,ost,x,y):
    xx=steps[1]-steps[3]
    yy=steps[0]-steps[2]
    return distance(x,y,xx,yy)<=ost



ans=0


if distance(x,y,0,0)>n or (x+y+n)%2==1:
    print(-1)
elif yes(it,0,x,y):
    print(0)
else:
    i=-1
    cur_ans=0
    max_ans=0

    steps=[0,0,0,0]
    
    while yes(steps,n-cur_ans,x,y):
        i+=1
        steps[s[i]]+=1
        cur_ans+=1

    steps[s[i]]-=1
    i-=1
    cur_ans-=1
    max_ans=cur_ans

    j=n
    ok=True

    while j>0 and ok:
        j=j-1
        steps[s[j]]+=1
        cur_ans+=1
        
        while i>=0 and not yes(steps,n-cur_ans,x,y):
            steps[s[i]]-=1
            i-=1
            cur_ans-=1
        
        if yes(steps,n-cur_ans,x,y) and cur_ans>max_ans:
            max_ans=cur_ans
        ok=(i>=0) or yes(steps,n-cur_ans,x,y)

    print(n-max_ans)




import sys
fin = sys.stdin.readline

n = int(fin())
commands = list(fin())[:-1]
x, y = [int(elem) for elem in fin().split(' ')]

move_map = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}

if (x + y) % 2 != n % 2:
    print(-1)
    return

cuml_coord = [None] * n
cuml_x, cuml_y = 0, 0
for i, command in enumerate(commands):
    dx, dy = move_map[command]
    cuml_x += dx
    cuml_y += dy
    cuml_coord[i] = (cuml_x, cuml_y)

left, right = 0, 0
min_len = 2**32 - 1
org_x, org_y = cuml_coord[-1]
if org_x == x and org_y == y:
    min_len = 0

while right <= n - 1:
    if left == 0:
        left_cuml = 0, 0
    else:
        left_cuml = cuml_coord[left - 1]
    right_cuml = cuml_coord[right]
    movable_x, movable_y = right_cuml[0] - left_cuml[0], \
                           right_cuml[1] - left_cuml[1]
    fixed_x, fixed_y = org_x - movable_x, org_y - movable_y
    sub_length = right - left + 1
    # print(fixed_x, fixed_y, left, right)
    # print(x - fixed_x, y - fixed_y)
    if (abs(x - fixed_x) + abs(y - fixed_y)) <= sub_length \
    and (abs(x - fixed_x) + abs(y - fixed_y)) % 2 == sub_length % 2:
        min_len = min(min_len, sub_length)
        if left != right:
            left += 1
        else:
            right += 1
    else:
        right += 1
if min_len == 2**32 - 1:
    print(-1)
else:
    print(min_len)


import sys
fin = sys.stdin.readline

n = int(fin())
commands = list(fin())[:-1]
x, y = [int(elem) for elem in fin().split(' ')]

move_map = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}

if (x + y) % 2 != n % 2:
    print(-1)
    return

cuml_coord = [None] * n
cuml_x, cuml_y = 0, 0
for i, command in enumerate(commands):
    dx, dy = move_map[command]
    cuml_x += dx
    cuml_y += dy
    cuml_coord[i] = (cuml_x, cuml_y)

left, right = 0, 0
min_len = 2**32 - 1
org_x, org_y = cuml_coord[-1]
if org_x == x and org_y == y:
    min_len = 0

while right <= n - 1:
    if left == 0:
        left_cuml = 0, 0
    else:
        left_cuml = cuml_coord[left - 1]
    right_cuml = cuml_coord[right]
    movable_x, movable_y = right_cuml[0] - left_cuml[0], \
                           right_cuml[1] - left_cuml[1]
    fixed_x, fixed_y = org_x - movable_x, org_y - movable_y
    sub_length = right - left + 1
    # print(fixed_x, fixed_y, left, right)
    # print(x - fixed_x, y - fixed_y)
    if (abs(x - fixed_x) + abs(y - fixed_y)) <= sub_length \
    and (abs(x - fixed_x) + abs(y - fixed_y)) % 2 == sub_length % 2:
        min_len = min(min_len, sub_length)
        if left != right:
            left += 1
        else:
            right += 1
    else:
        right += 1
if min_len == 2**32 - 1:
    print(-1)
else:
    print(min_len)


import math as ma
import sys
from decimal import Decimal as dec
from itertools import permutations


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


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


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


def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x

n=nu()
s=input()
x,y=num()
uu=[0]*n
rr=[0]*n
pu=[]
pr=[]
for i in range(n):
	if(s[i]=="U"):
		uu[i]=1
	if(s[i]=="D"):
		uu[i] = -1
	if(s[i]=="R"):
		rr[i]=1
	if(s[i]=="L"):
		rr[i]=-1

pu.append(uu[0])
pr.append(rr[0])
for i in range(1,n):
	pu.append(pu[i-1]+uu[i])
for i in range(1,n):
	pr.append(pr[i-1]+rr[i])
pu=[0]+pu
pr=[0]+pr
zu=pu[len(pu)-1]
zr=pr[len(pr)-1]
if((abs(x-zr)+abs(y-zu))==0):
	print(0)
	return
if((abs(x)+abs(y))%2!=n%2 or (abs(x)+abs(y))>n):
	print(-1)
	return

lo=1
hi=n
while(lo<=hi):
	mid=(lo+hi)//2
	fl=False
	for i in range(0,n-mid+1):
		lu=zu-pu[i+mid]+pu[i]
		lr=zr-pr[i+mid]+pr[i]
		if((abs(x-lr)+abs(y-lu))<=mid):
			fl=True
			break
	if(fl==True):
		hi=mid-1
	else:
		lo=mid+1
print(lo)

n = int(input().strip())
s = str(input().strip())
x,y = list(map(int,input().strip().split()))
sumx = []
sumy = []

sx = 0
sy = 0
sumx.append(sx)
sumy.append(sy)
for i in s:
    if(i=='U'):
        sy+=1
    elif(i=='D'):
        sy-=1
    elif(i=='R'):
        sx+=1
    elif(i=='L'):
        sx-=1
    sumx.append(sx)
    sumy.append(sy)

#print("sxy",sx, sy)

def check(mid):
    i=0
    while(i+mid<=n):
        dx = sumx[i+mid]-sumx[i]
        dy = sumy[i+mid]-sumy[i]
        cx = sx-dx
        cy = sy-dy
        #print("cxy",cx,cy)
        gdx = x-cx
        gdy = y-cy
        t=abs(gdx)+abs(gdy)
        #print("t",t)
        if(t%2==mid%2 and t<=mid):
            return True
        i+=1
    return False

hi = n
lo = 0
mid=(hi+lo)//2
while(hi-lo>1):
    mid=(hi+lo)//2
    #print("mid", mid)
    if(check(mid)):
        hi=mid
    else:
        lo=mid
#print(lo)
if(check(lo)):
    print(lo)
elif(check(mid)):
    print(mid)
elif(check(hi)):
    print(hi)
else:
    print(-1)

def check(x, y, fx, fy, num_moves):
	if ((abs(fx - x) +  abs(fy - y))-num_moves) <= 0 and ((abs(fx - x) +  abs(fy - y))-num_moves)%2  == 0:
		return True
	return False 

N = int(input())
mm =  {'U':0,'D':1,'L':2,'R':3}

dpmat = [[0] for i in range(4)]

ops =  str(input())

for op in ops:
	dpmat[0].append(dpmat[0][-1])
	dpmat[1].append(dpmat[1][-1])
	dpmat[2].append(dpmat[2][-1])
	dpmat[3].append(dpmat[3][-1])
	
	dpmat[mm[op]][-1] = dpmat[mm[op]][-1]+1


fpos = list(map(int,input().split())) 
if N < fpos[0]+fpos[1]:
	print("-1")
else :
	x,y = 0,0

	ans = 10e10

	while y <= N and x <= y:
		if y == 0 and x == 0:	
			num_moves = 0
			xr = dpmat[3][N]
			xl = dpmat[2][N]
			yu = dpmat[0][N]
			yd = dpmat[1][N]
		else:
			num_moves = y-x+1
			xr = dpmat[3][x-1] +  dpmat[3][N] - dpmat[3][y]	
			xl = dpmat[2][x-1] +  dpmat[2][N] - dpmat[2][y]	
			yu = dpmat[0][x-1] +  dpmat[0][N] - dpmat[0][y]	
			yd = dpmat[1][x-1] +  dpmat[1][N] - dpmat[1][y]	
		
		if check(xr-xl, yu-yd, fpos[0], fpos[1], num_moves) == True:
			x += 1
			ans = min(ans, num_moves)
		else:
			if x==0:
				x += 1	
			y += 1
	if ans == 10e10:
		print("-1")
	else:
		print(max(0,ans))


3
from collections import Counter

def readint():
    return int(input())


def readline():
    return [int(c) for c in input().split()]


def update(pos, mv, d):
    if mv == 'U':
        pos[1] += d
    elif mv == 'D':
        pos[1] -= d
    elif mv == 'L':
        pos[0] -= d
    elif mv == 'R':
        pos[0] += d


def can(u, v, length):
    d = abs(u[0] - v[0]) + abs(u[1] - v[1])
    if d % 2 != length % 2:
        return False
    return length >= d


def ok(length, n, x, y, s):
    pos = [0, 0]
    for i in range(length, n):
        update(pos, s[i], 1)

    l, r = 0, length
    while True:
        if can(pos, [x, y], length):
            return True
        if r == n:
            break
        update(pos, s[l], 1)
        l += 1
        update(pos, s[r], -1)
        r += 1

    return False


def main():
    n = readint()
    s = input()
    x, y = readline()

    if not ok(n, n, x, y, s):
        print(-1)
        return

    l, r = -1, n
    while r - l > 1:
        mid = (l + r) // 2
        if ok(mid, n, x, y, s):
            r = mid
        else:
            l = mid
            
    print(r)

    


def __starting_point():
    main()


"""
#include <bits/stdc++.h>

using namespace std;

const int N = int(1e5) + 9;

string s;
int n;
int x, y;

void upd(pair<int, int> &pos, char mv, int d){
	if(mv == 'U')
		pos.second += d;
	if(mv == 'D')
		pos.second -= d;
	if(mv == 'L')
		pos.first -= d;
	if(mv == 'R')
		pos.first += d;
}

bool can(pair<int, int> u, pair<int, int> v, int len){
	int d = abs(u.first - v.first) + abs(u.second - v.second);
	if(d % 2 != len % 2) return false;
	return len >= d;
}

bool ok(int len){
	pair<int, int> pos = make_pair(0, 0);
	for(int i = len; i < n; ++i)
		upd(pos, s[i], 1);

	int l = 0, r = len;
	while(true){
		if(can(pos, make_pair(x, y), len))
			return true;
		
		if(r == n) break;
		upd(pos, s[l++], 1);
		upd(pos, s[r++], -1);		
	}
	
	return false;
}

int main() {
	//freopen("input.txt", "r", stdin);
	
	cin >> n;
	cin >> s;
	cin >> x >> y;
	
	if(!ok(n)){
		puts("-1");
		return 0;
	}
	
	int l = -1, r = n;
	while(r - l > 1){
		int mid = (l + r) / 2;
		if(ok(mid)) r = mid;
		else l = mid;
	}
	
	cout << r << endl;
    return 0;
}
"""

__starting_point()

d = {
	'U': (0, 1),
	'D': (0, -1),
	'L': (-1, 0),
	'R': (1, 0)
}


def compute_delta(s, head_idx, tail_idx):
	x = y = 0
	for i in range(head_idx, tail_idx):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	return x, y


def compute_rest(s, n, head_idx, tail_idx):
	x = y = 0
	for i in range(0, head_idx):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	for i in range(tail_idx, n):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	return x, y


n = int(input())
s = input()
x_d, y_d = list(map(int, input().split()))
# n = 5
# s = 'RURUU'
# x_d, y_d = -2, 3
x_t, y_t = compute_delta(s, 0, n)

# if x_d == x_t and y_d == y_t:
#    print(0)

l, r = 0, n
current_sol = -1
while l <= r:
	# print(l, r)
	local_len = (r + l) // 2

	x_l, y_l = compute_rest(s, n, 0, local_len)
	# print('local_len: ', local_len)
	is_possible = False
	diff = abs(x_d - x_l) + abs(y_d - y_l)
	if diff <= local_len and (diff + local_len) % 2 == 0:
		is_possible = True
	# print('\t', x_l, y_l, abs(x_d - x_l), abs(y_d - y_l), local_len, is_possible)
	for i in range(local_len, n):
		if is_possible:
			break
		d_old, d_new = d[s[i]], d[s[i - local_len]]
		x_l, y_l = x_l - d_old[0] + d_new[0], y_l - d_old[1] + d_new[1]
		# print('\t', x_l, y_l, abs(x_d - x_l), abs(y_d - y_l), local_len)
		diff = abs(x_d - x_l) + abs(y_d - y_l)
		if diff <= local_len and (diff + local_len) % 2 == 0:
			is_possible = True
	# print(l, r, local_len, current_sol, is_possible)
	if is_possible:
		current_sol = local_len
		r = local_len - 1
	else:
		l = local_len + 1
print(current_sol)

d = {
	'U': (0, 1),
	'D': (0, -1),
	'L': (-1, 0),
	'R': (1, 0)
}


def compute_delta(s, head_idx, tail_idx):
	x = y = 0
	for i in range(head_idx, tail_idx):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	return [x, y]


n = int(input())
s = input()
dsc = list(map(int, input().split()))
total = compute_delta(s, 0, n)

l, r = 0, n
current_sol = -1
while l <= r:
	local_len = (r + l) // 2
	initial_diff = compute_delta(s, 0, local_len)
	local = [total[0] - initial_diff[0], total[1] - initial_diff[1]]
	is_possible = False
	diff = abs(dsc[0] - local[0]) + abs(dsc[1] - local[1])
	if diff <= local_len and (diff + local_len) % 2 == 0:
		is_possible = True
	for i in range(local_len, n):
		if is_possible:
			break
		d_old, d_new = d[s[i]], d[s[i - local_len]]
		local = [local[0] - d_old[0] + d_new[0], local[1] - d_old[1] + d_new[1]]
		diff = abs(dsc[0] - local[0]) + abs(dsc[1] - local[1])
		if diff <= local_len and (diff + local_len) % 2 == 0:
			is_possible = True
	if is_possible:
		current_sol = local_len
		r = local_len - 1
	else:
		l = local_len + 1
print(current_sol)


# -*- coding: utf-8 -*-

"""
created by shhuan at 2018/11/3 11:30


search for minimum steps, consider binary search

"""

N = int(input())
ops = [x for x in input()]

X, Y = list(map(int, input().split()))

dd = abs(X) + abs(Y)
lops = len(ops)
# if dd > lops or (lops - dd) % 2 != 0:
#     print(-1)
#     return


[ll, lr, lu, ld, rl, rr, ru, rd] = [[0 for _ in range(lops + 2)] for _ in range(8)]

l, r, u, d = 0, 0, 0, 0
for i in range(lops):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    ll[i+1] = l
    lr[i+1] = r
    ld[i+1] = d
    lu[i+1] = u

l, r, u, d = 0, 0, 0, 0
for i in range(lops-1, -1, -1):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    rl[i] = l
    rr[i] = r
    rd[i] = d
    ru[i] = u

def check(lsub):
    for i in range(lops-lsub+1):
        # j-i+1 == lsub, j < lops => i+lsub-1 <lops => i < lops-lsub+1
        j = i + lsub - 1

        # l, r, u, d of lops [0, i-1], ll[i]={'L' of 0,...,i-1}
        l0, r0, u0, d0 = ll[i], lr[i], lu[i], ld[i]

        # l, r, u, d of ops [j+1, N-1], rr[j]={'R' of lops-1,...,j}
        l1, r1, u1, d1 = rl[j+1], rr[j+1], ru[j+1], rd[j+1]

        x = (r0+r1) - (l0+l1)
        y = (u0+u1) - (d0+d1)

        dx = abs(X-x)
        dy = abs(Y-y)

        if dx + dy <= lsub and (lsub-dx-dy) % 2 == 0:
            return True

    return False


sl, sr = 0, lops + 1
while sl < sr:
    m = (sl + sr) // 2
    if check(m):
        sr = m
    else:
        sl = m + 1

sl = -1 if sl > lops else sl
print(sl)





# -*- coding: utf-8 -*-

"""
created by shhuan at 2018/11/3 11:30


search for minimum steps, consider binary search

"""

N = int(input())
ops = [x for x in input()]

X, Y = list(map(int, input().split()))

dd = abs(X) + abs(Y)
lops = len(ops)
if dd > lops or (lops - dd) % 2 != 0:
    print(-1)
    return


[ll, lr, lu, ld, rl, rr, ru, rd] = [[0 for _ in range(lops + 2)] for _ in range(8)]

l, r, u, d = 0, 0, 0, 0
for i in range(lops):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    ll[i+1] = l
    lr[i+1] = r
    ld[i+1] = d
    lu[i+1] = u

l, r, u, d = 0, 0, 0, 0
for i in range(lops-1, -1, -1):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    rl[i] = l
    rr[i] = r
    rd[i] = d
    ru[i] = u

def check(lsub):
    for i in range(lops-lsub+1):
        # j-i+1 == lsub, j < lops => i+lsub-1 <lops => i < lops-lsub+1
        j = i + lsub - 1

        # l, r, u, d of lops [0, i-1], ll[i]={'L' of 0,...,i-1}
        l0, r0, u0, d0 = ll[i], lr[i], lu[i], ld[i]

        # l, r, u, d of ops [j+1, N-1], rr[j]={'R' of lops-1,...,j}
        l1, r1, u1, d1 = rl[j+1], rr[j+1], ru[j+1], rd[j+1]

        x = (r0+r1) - (l0+l1)
        y = (u0+u1) - (d0+d1)

        dx = abs(X-x)
        dy = abs(Y-y)

        if dx + dy <= lsub and (lsub-dx-dy) % 2 == 0:
            return True

    return False


sl, sr = 0, lops + 1
while sl < sr:
    m = (sl + sr) // 2
    if check(m):
        sr = m
    else:
        sl = m + 1

sl = -1 if sl > lops else sl
print(sl)





n = int(input())
dirs = input()
goal = list(map(int, input().split(' ')))


def can(start, end, steps):
    dist = abs(start[0] - end[0]) + abs(start[1] - end[1])
    return dist <= steps and (steps - dist) % 2 == 0


if not can((0, 0), goal, n):
    print(-1)
    return

diffs = {
    'U': (0, 1),
    'D': (0, -1),
    'L': (-1, 0),
    'R': (1, 0),
}

pos = [(0, 0)] + [None] * n
for i, dir in enumerate(dirs):
    old_pos = pos[i]
    diff = diffs[dir]
    pos[i+1] = (old_pos[0] + diff[0], old_pos[1] + diff[1])

final_pos = pos[n]

# best (minimum) segment to override to get to the solution
best = (abs(final_pos[0] - goal[0]) + abs(final_pos[1] - goal[1])) // 2

if best == 0:
    print(0)
    return

start = 0
end = best

current_best = float('inf')

while end <= n:
    # exclude segment and check if can reach without
    cur_pos = (
        pos[start][0] + final_pos[0] - pos[end][0],
        pos[start][1] + final_pos[1] - pos[end][1],
    )

    if can(cur_pos, goal, end - start):
        current_best = min(current_best, end - start)
        if current_best == best:
            break
        start += 1
    else:
        end += 1

print(current_best)


# min_steps = abs(goal[0]) + abs(goal[1])
# if min_steps > n or (min_steps - n) % 2 != 0:
#     print(-1)
#     return

# cur_pos = [0, 0]
# for dir in dirs:
#     if dir == 'U':
#         cur_pos[1] += 1
#     if dir == 'D':
#         cur_pos[1] -= 1
#     if dir == 'L':
#         cur_pos[0] -= 1
#     if dir == 'R':
#         cur_pos[0] += 1

# pos_diff = [goal[0] - cur_pos[0], goal[1] - cur_pos[1]]

# vertical = abs(pos_diff[1]) > abs(pos_diff[0])
# up = pos_diff[1] > 0
# right = pos_diff[0] > 0
# replacement_steps = (abs(pos_diff[0]) + abs(pos_diff[1])) // 2
# diagonal_walk = replacement_steps - \
#     abs(abs(pos_diff[1]) - abs(pos_diff[0])) // 2

# start, end = 0, 0
# covered = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
# while end < n:
#     new_dir = dirs[end]
#     covered[new_dir] += 1
#     remaining = covered.copy()
#     end += 1

#     if vertical:
#         if up:
#             pass
#         else:
#             pass
#     else:
#         if right:
#             pass
#         else:
#             pass


#!/usr/bin/env python3

import itertools

def solve(L, n, px, py, x, y):
    for i in range(n):
        j = i + L
        if j > n:
            break
        dx = px[i] + px[-1] - px[j] - x
        dy = py[i] + py[-1] - py[j] - y
        if abs(dx) + abs(dy) <= L:
            return True
    return False

def main(args):
    n = int(input())
    d = input()
    x, y = list(map(int, input().split()))
    py = [0] + [1 if c == 'U' else (-1 if c == 'D' else 0) for c in d]
    px = [0] + [1 if c == 'R' else (-1 if c == 'L' else 0) for c in d]
    if abs(x+ y)%2 != n%2:
        print(-1)
        return 0
    py = list(itertools.accumulate(py))
    px = list(itertools.accumulate(px)) 
    if px[-1] == x and py[-1] == y:
        print(0)
        return 0
    if abs(x) + abs(y) > n:
        print(-1)
        return 0
    left = 0
    right = n
    while left + 1 < right:
        mid = (left + right) // 2
        if solve(mid, n, px, py, x, y):
            left, right = left, mid
        else:
            left, right = mid, right
    print(right)
    return 0

def __starting_point():
    import sys
    return(main(sys.argv))

__starting_point()

def go(pos,k):
    if 'U'==k:
        pos[1]+=1
    elif 'D'==k:
        pos[1]-=1
    elif 'L'==k:
        pos[0]-=1
    else:
        pos[0]+=1
    return pos

def relapos(a,b):           #返回b的坐标减a的坐标
    c=[b[0]-a[0],b[1]-a[1]]
    return c

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

n=int(input())
s=input()
x,y=[int(i) for i in input().split()]
poss=[[0,0]]             #第n次操作后的位置
pos=[0,0]
for i in range(0,n):
    poss.append(tuple(go(pos,s[i])))
if abs(x)+abs(y)>n or abs(n-x-y)%2!=0:
    print(-1)
else:
    lpos=poss[-1]
    dd=stdis(lpos,[x,y])
    if dd==0:
        print(0)
    else:
        q1=(dd-1)//2
        q2=n
        j=True
        lpos1=[0,0]
        while q2-q1!=1:
            q=(q2+q1)//2
            for k1 in range(n-q+1):
                r=relapos(poss[k1],poss[k1+q])
                lpos1[0]=lpos[0]-r[0]
                lpos1[1]=lpos[1]-r[1]
                if stdis(lpos1,[x,y])<=q:
                    q2=q
                    break
            else:
                q1=q
        print(q2)


n = int(input())
subtract = lambda t1, t2: (t1[0] - t2[0], t1[1] - t2[1])
add = lambda t1, t2: (t1[0] + t2[0], t1[1] + t2[1])
def conv(ch):
	if ch == 'L':
		return (-1, 0)
	elif ch == 'R':
		return (1, 0)
	elif ch == 'U':
		return (0, 1)
	elif ch == 'D':
		return (0, -1)

ops = [conv(ch) for ch in input()]
x, y = list(map(int, input().split()))
lsum = [ops[0]] * n
for i in range(1, n):
	lsum[i] = add(lsum[i - 1], ops[i])
rsum = [ops[n - 1]] * n
i = n - 2
while i >= 0:
	rsum[i] = add(rsum[i + 1], ops[i])
	i = i - 1

def check(L):
	
	for i in range(0, n - L + 1):
		moves = (x, y)
		if i > 0:
			moves = subtract(moves, lsum[i - 1])
		if i + L < n:
			moves = subtract(moves, rsum[i + L])
		turns = abs(moves[0]) + abs(moves[1])
		if (turns <= L and (L - turns) % 2 == 0):
			return True;
	return False;

if abs(x) + abs(y) > n or (abs(x) + abs(y) - n) % 2 != 0:
	print((-1));
else:
	st, en = 0, n
	while st < en:
		md = (st + en) // 2
		if check(md):
			en = md
		else:
			st = md + 1
	print(st)


def check(length: int):
    nonlocal n, x, y, cur, hor, ver
    hor = 0
    ver = 0
    for i in range(length, n):
        upd(i)
    for i in range(n - length + 1):
        if abs(x - hor) + abs(y - ver) <= length:
            return True
        if i + length < n:
            upd(i)
            minus_upd(i + length)
    return False


def upd(pos: int):
    nonlocal s, ver, hor
    if s[pos] == 'U':
        ver += 1
    elif s[pos] == 'D':
        ver -= 1
    elif s[pos] == 'R':
        hor += 1
    else:
        hor -= 1


def minus_upd(pos: int):
    nonlocal s, ver, hor
    if s[pos] == 'U':
        ver -= 1
    elif s[pos] == 'D':
        ver += 1
    elif s[pos] == 'R':
        hor -= 1
    else:
        hor += 1


n = int(input())
s = list(input())
x, y = map(int, input().split())
if (x + y) % 2 != n % 2 or abs(x) + abs(y) > n:
    print(-1)
    return

ver = 0
hor = 0
cur = 0
for i in range(n):
    upd(i)

left = -1
r = n
while r - left > 1:
    length = (r + left) // 2
    if check(length):
        r = length
    else:
        left = length

print(r)

n=int(input())
a=input()
x,y=map(int,input().split())
locs=[(0,0)]
for i in range(n):
    if a[i]=="U":
        locs.append((locs[-1][0],locs[-1][1]+1))
    elif a[i]=="D":
        locs.append((locs[-1][0],locs[-1][1]-1))
    elif a[i]=="R":
        locs.append((locs[-1][0]+1,locs[-1][1]))
    else:
        locs.append((locs[-1][0]-1,locs[-1][1]))
if abs(x)+abs(y)>n or (x+y-n)%2==1:
    print(-1)
elif locs[-1]==(x,y):
    print(0)
else:
    a=0
    b=0
    best=n
    end=locs[-1]
    while True:
        c,d=locs[a][0]+end[0]-locs[b][0],locs[a][1]+end[1]-locs[b][1]
        if abs(c-x)+abs(d-y)<=b-a:
            best=min(best,b-a)
            a+=1
        else:
            b+=1
            if b>n:
                print(best)
                break

import functools

n = int(input())
dct = {'U': (0, 1), 'D': (0, -1), 'L': (-1, 0), 'R': (1, 0)}
moves_list = list([dct[x] for x in [*input()]])
dest_x, dest_y = list(map(int, input().split()))


def add_vectors(a, b):
    return a[0] + b[0], a[1] + b[1]


def subtract_vectors(a, b):
    return a[0] - b[0], a[1] - b[1]


total = functools.reduce(add_vectors, moves_list)


def czy(dl) -> bool:
    sumo = total
    for v in moves_list[:dl]:
        sumo = subtract_vectors(sumo, v)
    for i in range(1, n - dl + 2):
        (dx, dy) = list(map(abs, subtract_vectors((dest_x, dest_y), sumo)))
        if dx + dy <= dl and (dx + dy) % 2 == dl % 2:
            return True
        if i + dl - 1 >= n:
            break
        sumo = subtract_vectors(sumo, moves_list[i + dl - 1])
        sumo = add_vectors(sumo, moves_list[i - 1])
    return False


pocz = 0
kon = n
while pocz < kon:
    sr = (pocz + kon) // 2
    if czy(sr):
        kon = sr
    else:
        pocz = sr + 1

if czy(pocz):
    print(pocz)
else:
    print(-1)