Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left.  An 'R' indicates he should move one unit right.  A 'U' indicates he should move one unit up.  A 'D' indicates he should move one unit down.

But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.


-----Input-----

The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.


-----Output-----

If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.


-----Examples-----
Input
RRU

Output
-1

Input
UDUR

Output
1

Input
RUUR

Output
2



-----Note-----

In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.

In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation


Solutions:
s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	hor = 0
	ver = 0
	for direction in s:
		if direction == 'R':
			hor += 1
		elif direction == 'L':
			hor -= 1
		elif direction == 'U':
			ver += 1
		else:
			ver -= 1
	print((abs(hor) + abs(ver)) // 2)


n = input()
r = 0
c = 0
if len(n) % 2 == 1:
	print('-1')
else:
	for i in n:
		if i == 'U':
			c += 1
		elif i == 'D':
			c -= 1
		elif i == 'L':
			r += 1
		else:
			r -= 1
	print((abs(r) + abs(c)) // 2)


dic = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
data = input()
for x in data:
	dic[x] = dic[x] + 1
if len(data) % 2 == 1:
	print('-1')
else:
	print(abs(dic['U'] - dic['D']) + abs(dic['L'] - dic['R']) >> 1)


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	r = 0
	l = 0
	u = 0
	d = 0
	res1 = 0
	res2 = 0
	for i in range(len(s)):
		if s[i] == 'L':
			l += 1
		elif s[i] == 'R':
			r += 1
		elif s[i] == 'D':
			d += 1
		else:
			u += 1
	res1 = abs(d - u)
	res2 = abs(r - l)
	c = 0
	if res1 % 2 == 0:
		c += res1 // 2
		c += res2 // 2
	else:
		c += res1 // 2
		c += res2 // 2
		c += 1
	print(c)


import collections

def main():
	s = input()
	if len(s) % 2 == 1:
		print(-1)
		return
	ct = collections.Counter(s)
	print((abs(ct['L'] - ct['R']) + abs(ct['U'] - ct['D'])) // 2)
main()


import math
s = input()
ans = 0
u = 0
d = 0
l = 0
r = 0
if len(s) % 2 != 0:
	print('-1')
else:
	for i in s:
		if i == 'D':
			d += 1
		elif i == 'U':
			u += 1
		elif i == 'L':
			l += 1
		elif i == 'R':
			r += 1
	print(int((abs(r - l) + abs(u - d)) / 2))


s = input()
if len(s) % 2:
	print(-1)
	exit()
u = d = l = r = 0
for i in range(len(s)):
	if s[i] == 'U':
		u += 1
	elif s[i] == 'D':
		d += 1
	elif s[i] == 'L':
		l += 1
	else:
		r += 1
if u < d:
	t = u
	u = d
	d = t
if r < l:
	t = r
	r = l
	l = t
if (u - d) % 2:
	u += 1
	r -= 1
print((u - d) // 2 + (r - l) // 2)


s = input()
countr = 0
countu = 0
for i in s:
	if i == 'U':
		countu += 1
	elif i == 'D':
		countu -= 1
	elif i == 'R':
		countr += 1
	else:
		countr -= 1
if (countr + countu) % 2 == 1:
	print(-1)
else:
	print((abs(countr) + abs(countu)) // 2)


s = input()
if len(s) % 2:
	print(-1)
	exit()
x = 0
y = 0
for i in s:
	if i == 'L':
		x -= 1
	if i == 'R':
		x += 1
	if i == 'U':
		y += 1
	if i == 'D':
		y -= 1
x = abs(x)
y = abs(y)
print(x // 2 + y // 2 + max(x % 2, y % 2))


s = input()
l = len(s)
if l % 2 == 1:
	print(-1)
else:
	u = s.count('U')
	d = s.count('D')
	l = s.count('L')
	r = s.count('R')
	ud = abs(u - d) // 2
	v1 = abs(u - d) % 2
	rl = abs(l - r) // 2
	v2 = abs(l - r) % 2
	total = ud + rl
	total += (v1 + v2) // 2
	print(total)


A = input()
cntu = 0
cntr = 0
for x in A:
	if x == 'R':
		cntr += 1
	elif x == 'L':
		cntr -= 1
	elif x == 'U':
		cntu += 1
	else:
		cntu -= 1
cntu = abs(cntu)
cntr = abs(cntr)
if cntu % 2 and cntr % 2:
	cntu -= 1
	cntr += 1
if cntu % 2 or cntr % 2:
	print(-1)
else:
	print(cntu // 2 + cntr // 2)


s = input()
if len(s) % 2 == 1:
	print('-1')
else:
	x = 0
	y = 0
	for i in s:
		if i == 'U':
			y += 1
		elif i == 'D':
			y -= 1
		elif i == 'R':
			x += 1
		else:
			x -= 1
	print((abs(x) + abs(y)) // 2)


s = input()
(r, l, d, u) = (s.count('R'), s.count('L'), s.count('U'), s.count('D'))
(a, b) = (abs(r - l), abs(d - u))
if (a + b) % 2 == 1:
	print(-1)
else:
	print(int(abs(a - b) + (a + b - 2 * abs(a - b)) / 2))


s = input()
if len(s) % 2:
	print(-1)
else:
	a = s.count('U')
	b = s.count('D')
	c = s.count('L')
	d = s.count('R')
	x = abs(a - b)
	y = abs(c - d)
	if (x + y) % 2:
		print(-1)
	else:
		print((x + y) // 2)


s = input()
if len(s) % 2 == 1:
	print(-1)
	exit()
horizontal = 0
vertical = 0
for k in s:
	if k == 'L':
		horizontal += 1
	elif k == 'R':
		horizontal -= 1
	elif k == 'U':
		vertical += 1
	elif k == 'D':
		vertical -= 1
horizontal = abs(horizontal)
vertical = abs(vertical)
print((horizontal + vertical) // 2)


import math
step = input()
if len(step) % 2 != 0:
	print('-1')
else:
	dic = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for i in step:
		dic[i] += 1
	a = abs(dic['L'] - dic['R'])
	b = abs(dic['U'] - dic['D'])
	print(int((a + b) / 2))


s = input()
U = 0
D = 0
L = 0
R = 0
for ch in s:
	if ch == 'U':
		U += 1
	if ch == 'D':
		D += 1
	if ch == 'L':
		L += 1
	if ch == 'R':
		R += 1
if (U + D + R + L) % 2 == 1:
	print('-1')
else:
	changeup = abs(U - D) / 2
	changel = abs(L - R) / 2
	print(int(changeup + changel))


import sys

def read_data():
	s = next(sys.stdin).strip()
	(a, b, c, d) = (0, 0, 0, 0)
	for ch in s:
		if ch == 'R':
			a += 1
		elif ch == 'L':
			b += 1
		elif ch == 'U':
			c += 1
		elif ch == 'D':
			d += 1
		else:
			raise RuntimeError('')
	return (a, b, c, d)

def solve(a, b, c, d):
	T = a + b + c + d
	if T % 2 != 0:
		return -1
	t = T // 2
	best = None
	for x in range(0, t + 1):
		y = t - x
		cnt = (a - x if a > x else 0) + (b - x if b > x else 0) + (c - y if c > y else 0) + (d - y if d > y else 0)
		if best is None or cnt < best:
			best = cnt
	return best
(a, b, c, d) = read_data()
print(solve(a, b, c, d))


(RL, UD, X) = (0, 0, input())
for i in X:
	if i in 'UD':
		UD += 1 if i == 'U' else -1
	if i in 'RL':
		RL += 1 if i == 'R' else -1
Sum = abs(RL) + abs(UD)
print(-1 if len(X) % 2 == 1 else Sum // 2)


s = input().lower()
if len(s) % 2 == 1:
	print('-1')
	exit(0)
u = 0
d = 0
l = 0
r = 0
for c in s:
	if c == 'u':
		u += 1
	if c == 'd':
		d += 1
	if c == 'l':
		l += 1
	if c == 'r':
		r += 1
x = abs(l - r)
y = abs(u - d)
ans = 0
if x > y:
	ans += y
	if (x - y) % 2 == 0:
		ans += abs(x - y) // 2
	else:
		print(-1)
		exit(0)
if x < y:
	ans += x
	if (x - y) % 2 == 0:
		ans += abs(x - y) // 2
	else:
		print(-1)
		exit(0)
if abs(x - y) == 0:
	print(y)
	exit(0)
print(ans)


def compute():
	s = input()
	if len(s) % 2 == 1:
		return -1
	d = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for x in s:
		d[x] += 1
	return (abs(d['L'] - d['R']) + abs(d['U'] - d['D'])) // 2
print(compute())


str1 = input()
dic = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
l = len(str1)
if l % 2 != 0:
	print(-1)
	exit()
for i in str1:
	dic[i] += 1
s = (abs(dic['R'] - dic['L']) + abs(dic['U'] - dic['D'])) // 2
print(s)


s = input()
n = len(s)
if n % 2 == 1:
	print(-1)
else:
	a = abs(s.count('U') - s.count('D'))
	b = abs(s.count('L') - s.count('R'))
	ans = 0
	ans += a // 2 + b // 2
	if a % 2 == 1 or b % 2 == 1:
		ans += 1
	print(ans)


s = input()
lc = s.count('L')
rc = s.count('R')
dc = s.count('D')
uc = s.count('U')
x = abs(lc - rc) + abs(uc - dc)
if x & 1:
	print('-1')
else:
	print(x // 2)


s = str(input())
n = len(s)
r = 0
if n % 2:
	print(-1)
else:
	U = D = L = R = 0
	for i in range(n):
		if s[i] == 'L':
			L += 1
		elif s[i] == 'R':
			R += 1
		elif s[i] == 'U':
			U += 1
		else:
			D += 1
	if (U + D) % 2:
		r = 1
		if U > D:
			D += 1
			if R > L:
				R -= 1
			else:
				L -= 1
		else:
			U += 1
			if R > L:
				R -= 1
			else:
				L -= 1
	print(r + abs(U - D) // 2 + abs(R - L) // 2)


def main():
	arrow = input()
	(l, r, u, d) = (0, 0, 0, 0)
	for char in arrow:
		if char == 'L':
			l += 1
		elif char == 'R':
			r += 1
		elif char == 'U':
			u += 1
		elif char == 'D':
			d += 1
	if (l + r + d + u) % 2 != 0:
		print(-1)
		return
	change = (abs(l - r) + abs(u - d)) // 2
	print(change)
main()


def main():
	from sys import stdin, stdout
	s = stdin.readline().strip().lower()
	if len(s) & 1:
		stdout.write('-1')
	else:
		x = 0
		y = 0
		for i in s:
			if i == 'l':
				x -= 1
			elif i == 'r':
				x += 1
			elif i == 'u':
				y += 1
			elif i == 'd':
				y -= 1
		stdout.write(str((abs(x) + abs(y)) // 2))
main()


a = str(input())
b = len(a)
c = 0
d = 0
if b % 2 == 1:
	print(-1)
	exit()
for i in range(b):
	if a[i] == 'R':
		c += 1
	if a[i] == 'L':
		c -= 1
	if a[i] == 'U':
		d += 1
	if a[i] == 'D':
		d -= 1
print((abs(c) + abs(d)) // 2)


s = input()
l = 0
r = 0
u = 0
d = 0
for c in s:
	if c == 'R':
		r += 1
	elif c == 'L':
		l += 1
	elif c == 'U':
		u += 1
	elif c == 'D':
		d += 1
d1 = max(l, r) - min(l, r)
d2 = max(u, d) - min(u, d)
if (d1 + d2) % 2 != 0:
	print(-1)
else:
	print((d1 + d2) // 2)


def solve(ins):
	if len(ins) % 2 != 0:
		return -1
	else:
		half = len(ins) // 2
		ans = 0
		canceled = 0
		refer = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
		cross = {'U': 'D', 'D': 'U', 'L': 'R', 'R': 'L'}
		for x in ins:
			refer[x] += 1
		canceled += min(refer['U'], refer['D']) * 2
		canceled += min(refer['L'], refer['R']) * 2
		ans = (len(ins) - canceled) // 2
		return ans
print(solve(input()))


commands = input()
if len(commands) % 2 != 0:
	print(-1)
else:
	left_right = 0
	top_bot = 0
	for i in commands:
		if i == 'R':
			left_right += 1
		elif i == 'L':
			left_right -= 1
		elif i == 'U':
			top_bot += 1
		elif i == 'D':
			top_bot -= 1
	print((abs(top_bot) + abs(left_right)) // 2)


def main():
	s = input()
	R = s.count('R')
	L = s.count('L')
	U = s.count('U')
	D = s.count('D')
	ans = -1
	if (R + L + U + D) % 2 == 0:
		if R == L and U == D:
			print('0')
		else:
			ans = (abs(R - L) + abs(U - D)) // 2
			print(ans)
	else:
		print('-1')
main()


vert = 0
hor = 0
s = input()
for i in s:
	if i == 'U':
		vert += 1
	elif i == 'D':
		vert -= 1
	elif i == 'R':
		hor += 1
	elif i == 'L':
		hor -= 1
if len(s) % 2 == 0:
	print((abs(vert) + abs(hor)) // 2)
else:
	print(-1)


def find_minimum_change():
	instruction = input()
	if len(instruction) % 2 == 1:
		print('-1')
	else:
		horizen_distance = vertical_distance = 0
		for character in range(0, len(instruction)):
			if instruction[character] == 'L':
				horizen_distance += 1
			elif instruction[character] == 'R':
				horizen_distance -= 1
			elif instruction[character] == 'U':
				vertical_distance += 1
			else:
				vertical_distance -= 1
		number_of_changes = (abs(vertical_distance) + abs(horizen_distance)) / 2
		print(int(number_of_changes))
find_minimum_change()


commands = input()
nl = commands.count('L')
nr = commands.count('R')
nu = commands.count('U')
nd = commands.count('D')
if len(commands) % 2 != 0:
	print(-1)
else:
	dh = abs(nl - nr)
	dv = abs(nu - nd)
	if dh + dv == 0:
		print(0)
	elif dh % 2 == 0:
		print(dh // 2 + dv // 2)
	else:
		if dh < dv:
			(dh, dv) = (dv, dh)
		print((dh - 1) // 2 + (dv - 1) // 2 + 1)


st = input()
a = [0] * 4
if len(st) % 2 == 1:
	print(-1)
else:
	for char in st:
		if char == 'L':
			a[0] += 1
		elif char == 'R':
			a[1] += 1
		elif char == 'U':
			a[2] += 1
		elif char == 'D':
			a[3] += 1
	maxn = max(abs(a[0] - a[1]), abs(a[2] - a[3]))
	minn = min(abs(a[0] - a[1]), abs(a[2] - a[3]))
	if (maxn - minn) % 2 == 1:
		print(-1)
	else:
		print(int(minn + (maxn - minn) / 2))


s = input()
r = s.count('R')
l = s.count('L')
u = s.count('U')
d = s.count('D')
x = max(l, r) - min(l, r)
y = max(u, d) - min(u, d)
if len(s) % 2 == 0:
	print((x + y) // 2)
else:
	print(-1)


x = input()
chap = 0
bala = 0
if len(x) % 2 == 1:
	print(-1)
else:
	for i in range(len(x)):
		if x[i] == 'R':
			chap -= 1
		elif x[i] == 'L':
			chap += 1
		elif x[i] == 'U':
			bala += 1
		else:
			bala -= 1
	if bala < 0:
		bala = -bala
	if chap < 0:
		chap = -chap
	r = min(chap, bala)
	chap = chap - r
	bala = bala - r
	if chap == 0:
		z = bala
	elif bala == 0:
		z = chap
	print(z // 2 + r)


n = input()
ans1 = 0
ans2 = 0
for i in n:
	if i == 'U':
		ans1 += 1
	elif i == 'D':
		ans1 -= 1
	elif i == 'R':
		ans2 += 1
	else:
		ans2 -= 1
ans1 = abs(ans1)
ans2 = abs(ans2)
if ans1 % 2 == 0 and ans2 % 2 == 0 or (ans1 % 2 == 1 and ans2 % 2 == 1):
	print((ans1 + ans2) // 2)
else:
	print(-1)


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	l = 0
	r = 0
	u = 0
	d = 0
	for i in s:
		if i == 'U':
			u += 1
		if i == 'D':
			d += 1
		if i == 'L':
			l += 1
		if i == 'R':
			r += 1
	t = min(abs(r - l), abs(u - d))
	print(t + (abs(r - l) - t) // 2 + (abs(u - d) - t) // 2)


st = input()
if len(st) % 2 == 1:
	print(-1)
else:
	lrcount = 0
	udcount = 0
	for ch in st:
		if ch == 'L':
			lrcount -= 1
		elif ch == 'R':
			lrcount += 1
		elif ch == 'U':
			udcount += 1
		else:
			udcount -= 1
	print((abs(lrcount) + abs(udcount)) // 2)


s = input()
if len(s) % 2 != 0:
	print('-1')
	exit()
L = 0
R = 0
U = 0
D = 0
for a in s:
	if a == 'L':
		L += 1
	elif a == 'R':
		R += 1
	elif a == 'D':
		D += 1
	else:
		U += 1
rem_L_R = abs(L - R)
rem_U_D = abs(U - D)
print(int(rem_U_D / 2 + rem_L_R / 2))


def main():
	string = input()
	if len(string) % 2 == 1:
		print(-1)
		return
	moves = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}
	cor = [0, 0]
	for i in string:
		cor[0] += moves[i][0]
		cor[1] += moves[i][1]
	print((abs(cor[0]) + abs(cor[1])) // 2)
main()


s = input()
if len(s) % 2 != 0:
	print(-1)
	exit()
(u, r) = (0, 0)
for i in range(len(s)):
	if s[i] == 'U':
		u += 1
	elif s[i] == 'D':
		u -= 1
	elif s[i] == 'R':
		r += 1
	else:
		r -= 1
r = abs(r)
u = abs(u)
q = max(r, u) - min(r, u)
mi = min(r, u)
print(q // 2 + mi)


s = input()
if len(s) % 2 == 0:
	(x, y) = (0, 0)
	for ch in s:
		if ch == 'L':
			x -= 1
		elif ch == 'R':
			x += 1
		elif ch == 'U':
			y += 1
		else:
			y -= 1
	print((abs(x) + abs(y)) // 2)
else:
	print(-1)


string = input()
length = len(string)
if length % 2 == 1:
	print(-1)
else:
	freq = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for x in string:
		freq[x] += 1
	steps = abs(freq['U'] - freq['D']) + abs(freq['L'] - freq['R'])
	print(int(steps / 2))


import sys, math
a = input()
n = len(a)
if n % 2 == 1:
	print(-1)
else:
	U = a.count('U')
	D = a.count('D')
	L = a.count('L')
	R = a.count('R')
	print(int(math.fabs(U - D) + math.fabs(L - R)) // 2)


s = input()
n = len(s)
cnt = [0 for i in range(4)]
for i in range(n):
	if s[i] == 'L':
		cnt[0] += 1
	elif s[i] == 'R':
		cnt[1] += 1
	elif s[i] == 'U':
		cnt[2] += 1
	else:
		cnt[3] += 1
if n % 2 != 0:
	print(-1)
else:
	diff1 = abs(cnt[0] - cnt[1])
	diff2 = abs(cnt[2] - cnt[3])
	if diff1 == 0 and diff2 == 0:
		print(0)
	elif diff1 % 2 == 0:
		print(int(diff1 / 2) + int(diff2 / 2))
	else:
		print(int(diff1 / 2) + int(diff2 / 2) + 1)


a = input()
(L, R, U, D) = (0, 0, 0, 0)
for i in a:
	if i == 'L':
		L += 1
	elif i == 'R':
		R += 1
	elif i == 'U':
		U += 1
	elif i == 'D':
		D += 1
UD = abs(U - D)
LR = abs(L - R)
if len(a) % 2 != 0:
	print('-1')
elif UD == 0 and LR == 0:
	print('0')
else:
	x = UD + LR
	if x % 2 != 0:
		print('-1')
	else:
		print(x // 2)


s = input()
(R, L, U, D) = (0, 0, 0, 0)
for i in s:
	if i == 'R':
		R += 1
	if i == 'L':
		L += 1
	if i == 'U':
		U += 1
	if i == 'D':
		D += 1
ans = max(R, L) - min(R, L) + max(U, D) - min(U, D)
if ans % 2 == 0:
	print(ans // 2)
else:
	print(-1)


s = input()
if len(s) % 2 == 1:
	print('-1')
	exit()
a = abs(s.count('U') - s.count('D'))
b = abs(s.count('L') - s.count('R'))
print(a + b >> 1)


s = input()
l = 0
r = 0
u = 0
d = 0
if len(s) % 2 != 0:
	print(-1)
else:
	for i in s:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	LR = abs(l - r)
	UD = abs(u - d)
	print(int((LR + UD) / 2))


s = input()
d = {'R': 'L', 'L': 'R', 'U': 'D', 'D': 'U'}
l_r = 0
u_d = 0
l = len(s)
if l & 1:
	print('-1')
else:
	ans = 0
	for i in range(l):
		if s[i] == 'R':
			l_r += 1
		elif s[i] == 'L':
			l_r -= 1
		elif s[i] == 'U':
			u_d += 1
		else:
			u_d -= 1
	t = abs(u_d) + abs(l_r)
	print(t // 2)


s = list(input())
d = s.count('D')
l = s.count('L')
r = s.count('R')
u = s.count('U')
if len(s) % 2 != 0:
	print('-1')
else:
	print(int(abs(l - r) / 2 + abs(u - d) / 2))


s = input()
(u, d, l, r) = [s.count(x) for x in 'UDLR']
ud = abs(u - d)
lr = abs(l - r)
if len(s) % 2:
	print(-1)
else:
	print(ud // 2 + lr // 2 + ud % 2)


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	p = 0
	kp = 0
	w = 0
	kw = 0
	for i in range(len(s)):
		if s[i] == 'R':
			p += 1
			kp += 1
		elif s[i] == 'L':
			p -= 1
			kp += 1
		elif s[i] == 'U':
			w += 1
			kw += 1
		else:
			w -= 1
			kw += 1
	print((abs(p) + abs(w)) // 2)


s = input()
r = l = d = u = 0
for i in s:
	if i == 'R':
		r += 1
	if i == 'L':
		l += 1
	if i == 'D':
		d += 1
	if i == 'U':
		u += 1
if (u + d + r + l) % 2 == 0:
	if u == d and r == l:
		print('0')
	else:
		print((abs(r - l) + abs(u - d)) // 2)
else:
	print('-1')


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	print((abs(s.count('R') - s.count('L')) + abs(s.count('U') - s.count('D'))) // 2)


w = list(input())
if len(w) % 2 == 1:
	print('-1')
else:
	r = 0
	u = 0
	for i in w:
		if i == 'R':
			r = r - 1
		elif i == 'L':
			r = r + 1
		elif i == 'D':
			u = u + 1
		else:
			u = u - 1
	if r < 0:
		r = -r
	if u < 0:
		u = -u
	k = r // 2 + u // 2 + r % 2
	print(k)


s = input()
i = 0
x = 0
y = 0
while i < len(s):
	if s[i] == 'R':
		x = x + 1
	if s[i] == 'L':
		x = x - 1
	if s[i] == 'U':
		y = y + 1
	if s[i] == 'D':
		y = y - 1
	i = i + 1
i = -1
if x < 0:
	x = -x
if y < 0:
	y = -y
x = x + y
if x % 2 == 0:
	print(x // 2)
else:
	print(i)


str = input()
if len(str) % 2:
	print(-1)
else:
	(x, y) = (0, 0)
	for i in str:
		if i == 'R':
			x += 1
		elif i == 'L':
			x -= 1
		elif i == 'U':
			y += 1
		else:
			y -= 1
	print((abs(x) + abs(y)) // 2)


s = input()
n = len(s)
if n % 2 != 0:
	print(-1)
else:
	a = s.count('U')
	b = s.count('D')
	c = s.count('L')
	d = s.count('R')
	if (a + b) % 2 == 0:
		print(abs(a - b) // 2 + abs(c - d) // 2)
	else:
		print(abs(a - b) // 2 + abs(c - d) // 2 + 1)


mod = 10 ** 9 + 7
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())
s = si()
sm = abs(s.count('R') - s.count('L')) + abs(s.count('U') - s.count('D'))
print([-1, sm // 2][not sm & 1])


s = str(input())
S = [str(i) for i in s]
x = 0
y = 0
if len(S) % 2 != 0:
	print(-1)
else:
	for i in S:
		if i == 'U':
			y += 1
		if i == 'D':
			y -= 1
		if i == 'R':
			x += 1
		if i == 'L':
			x -= 1
	if x < 0:
		x = x - 2 * x
	if y < 0:
		y = y - 2 * y
	print(int((x + y) / 2))


x = y = 0
for d in input():
	if 'L' == d:
		x -= 1
	elif 'R' == d:
		x += 1
	elif 'D' == d:
		y -= 1
	else:
		y += 1
y = abs(x) + abs(y)
print(-1 if 1 & y else y >> 1)


inp = input()

def left(coord):
	return (coord[0] - 1, coord[1])

def right(coord):
	return (coord[0] + 1, coord[1])

def up(coord):
	return (coord[0], coord[1] + 1)

def down(coord):
	return (coord[0], coord[1] - 1)
coord = (0, 0)
if len(inp) % 2 != 0:
	print('-1')
else:
	for move in inp:
		if move == 'L':
			coord = left(coord)
		if move == 'R':
			coord = right(coord)
		if move == 'U':
			coord = up(coord)
		if move == 'D':
			coord = down(coord)
	print(int((abs(coord[0]) + abs(coord[1])) / 2))


s = input()
if len(s) % 2 != 0:
	print(-1)
else:
	(l, r, u, d) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'U':
			u += 1
		elif s[i] == 'D':
			d += 1
		elif s[i] == 'R':
			r += 1
		else:
			l += 1
	print((abs(l - r) + abs(u - d)) // 2)


S = input()
l = 0
r = 0
u = 0
d = 0
if len(S) % 2 != 0:
	print(-1)
else:
	for i in S:
		if i == 'L':
			l += 1
		elif i == 'R':
			r += 1
		elif i == 'U':
			u += 1
		else:
			d += 1
	lr = abs(l - r)
	ud = abs(u - d)
	print(int((lr + ud) / 2))


s = input()
ans = 0
if len(s) % 2 != 0:
	print(-1)
else:
	u = s.count('U')
	d = s.count('D')
	r = s.count('R')
	l = s.count('L')
	if abs(u - d) % 2 == 0 and abs(r - l) % 2 == 0:
		ans = abs(u - d) // 2 + abs(r - l) // 2
	else:
		ans = abs(u - d) // 2 + abs(r - l) // 2 + 1
	print(ans)


s = input()
ans = -1
if len(s) % 2 == 0:
	UD = abs(s.count('U') - s.count('D'))
	LR = abs(s.count('L') - s.count('R'))
	ans = (UD + LR) // 2
print(ans)


l = input()
if len(l) % 2 != 0:
	print(-1)
elif l.count('R') == l.count('L') and l.count('U') == l.count('D'):
	print(0)
else:
	s = 0
	a = max(l.count('R'), l.count('L')) - min(l.count('R'), l.count('L'))
	b = max(l.count('U'), l.count('D')) - min(l.count('U'), l.count('D'))
	if a > b:
		a -= b
		s += b
		if a % 2 != 0:
			print(-1)
		else:
			print(s + a // 2)
	else:
		b -= a
		s += a
		if b % 2 == 0:
			print(s + b // 2)
		else:
			print(-1)


s = [0] * 86
for c in input():
	s[ord(c)] += 1
(h, v) = ((s[76], s[82]), (s[85], s[68]))
print(-1 if sum(s) & 1 else (max(h) + max(v) - min(h) - min(v)) // 2)


str = input()
if len(str) % 2 == 1:
	print(-1)
else:
	ver = 0
	hor = 0
	for i in str:
		if i == 'L':
			hor += 1
		if i == 'R':
			hor -= 1
		if i == 'U':
			ver += 1
		if i == 'D':
			ver -= 1
	print((abs(hor) + abs(ver)) // 2)


s = input()
if len(s) % 2:
	print(-1)
	exit()
li = {'U': 0, 'D': 1, 'L': 2, 'R': 3}
(dr, dc) = ([1, -1, 0, 0], [0, 0, -1, 1])
(r, c) = (0, 0)
for ch in s:
	r += dr[li[ch]]
	c += dc[li[ch]]
print((abs(r) + abs(c)) // 2)


x = 0
y = 0
s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	x = abs(s.count('L') - s.count('R'))
	y = abs(s.count('U') - s.count('D'))
	if x == len(s) or y == len(s):
		if x == len(s):
			print(len(s) // 2)
		else:
			print(len(s) // 2)
	elif x == 0 or y == 0:
		print(x // 2 if y == 0 else y // 2)
	elif x == y:
		print(x)
	else:
		t1 = min(x, y)
		t2 = max(x, y)
		res = t1 + (t2 - t1) // 2
		print(res)


import sys
f = sys.stdin
s = f.readline().strip()
if len(s) % 2 == 1:
	print(-1)
else:
	(r, u) = (0, 0)
	for c in s:
		if c == 'U':
			u += 1
		elif c == 'D':
			u -= 1
		elif c == 'R':
			r += 1
		else:
			r -= 1
	sum = abs(r) + abs(u)
	print(sum // 2)


way = list(input())
if len(way) % 2 == 1:
	print(-1)
else:
	rast = 0
	bala = 0
	for i in way:
		if i == 'R':
			rast -= 1
		elif i == 'L':
			rast += 1
		elif i == 'D':
			bala += 1
		else:
			bala -= 1
	if rast < 0:
		rast = -rast
	if bala < 0:
		bala = -bala
	t = rast // 2 + bala // 2 + rast % 2
	print(t)


inputString = input()
if len(inputString) & 1:
	print(-1)
	exit()
(DAmount, UAmount, LAmount, RAmount) = (0, 0, 0, 0)
for i in range(len(inputString)):
	if inputString[i] == 'D':
		DAmount += 1
	elif inputString[i] == 'U':
		UAmount += 1
	elif inputString[i] == 'L':
		LAmount += 1
	elif inputString[i] == 'R':
		RAmount += 1
DAmount = max(DAmount, UAmount) - min(DAmount, UAmount)
LAmount = max(LAmount, RAmount) - min(LAmount, RAmount)
ans = 0
ans += min(DAmount, LAmount)
(DAmount, LAmount) = (DAmount - min(DAmount, LAmount), LAmount - min(DAmount, LAmount))
if DAmount % 2 == 0 and LAmount % 2 == 0:
	print(ans + DAmount // 2 + LAmount // 2)
else:
	print(-1)


s = input()
if len(s) & 1:
	print('-1')
	exit(0)
print((abs(s.count('U') - s.count('D')) + abs(s.count('L') - s.count('R'))) // 2)


s = input()
li = s.count('L')
ri = s.count('R')
ui = s.count('U')
di = s.count('D')
n = len(s)
if n % 2 != 0:
	print(-1)
else:
	print((abs(li - ri) + abs(di - ui)) // 2)


s = list(input())
if len(s) % 2:
	print(-1)
	exit()
D = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}
(x, y) = (0, 0)
for c in s:
	x += D[c][0]
	y += D[c][1]
cnt = 0
for c in s:
	dx = D[c][0]
	dy = D[c][1]
	if abs(x + dx) <= abs(x) and abs(y + dy) <= abs(y):
		continue
	if abs(x) >= 2 and dx:
		x -= 2 * dx
		cnt += 1
	elif abs(y) >= 2 and dy:
		y -= 2 * dy
		cnt += 1
	elif abs(x) == 1 and abs(y) == 1:
		x = y = 0
		cnt += 1
print(cnt)


import math
import sys
import re

def func(s):
	if len(s) % 2 != 0:
		return -1
	else:
		a = abs(s.count('U') - s.count('D'))
		b = abs(s.count('L') - s.count('R'))
		return (a + b) // 2
s = input()
print(func(s))


s = input()
(hSum, vSum) = (0, 0)
(h, v) = (0, 0)
for i in s:
	if i == 'R':
		hSum += 1
		h += 1
	elif i == 'L':
		hSum -= 1
		h += 1
	elif i == 'U':
		vSum += 1
		v += 1
	else:
		vSum -= 1
		v += 1
print(-1 if (h + v) % 2 else (abs(hSum) + abs(vSum)) // 2)


s = input()
s = list(s)
u1 = s.count('U')
d1 = s.count('D')
l1 = s.count('L')
r1 = s.count('R')
k1 = abs(u1 - d1)
k2 = abs(l1 - r1)
if (k1 + k2) % 2 == 0:
	print((k1 + k2) // 2)
else:
	print('-1')


3
s = input()
if len(s) % 2 != 0:
	print(-1)
else:
	dy = s.count('U') - s.count('D')
	dx = s.count('R') - s.count('L')
	print((abs(dx) + abs(dy)) // 2)


S = input()
D = {'U': (0, 1), 'D': (0, -1), 'L': (-1, 0), 'R': (1, 0)}
x = y = 0
for c in S:
	(dx, dy) = D[c]
	x += dx
	y += dy
if len(S) % 2 == 1:
	print(-1)
else:
	print((abs(min(x, y)) + abs(max(x, y))) // 2)


import math
s = str(input())
if len(s) % 2 != 0:
	print(-1)
else:
	x = 0
	y = 0
	for i in range(0, len(s)):
		if s[i] == 'U':
			y = y + 1
		elif s[i] == 'D':
			y = y - 1
		elif s[i] == 'L':
			x = x + 1
		else:
			x = x - 1
	print((abs(x) + abs(y)) // 2)


def memory(s):
	if len(s) % 2 == 1:
		return -1
	else:
		return (abs(s.count('R') - s.count('L')) + abs(s.count('U') - s.count('D'))) // 2
t = input()
print(memory(t))


moves = list(input())
up = 0
down = 0
right = 0
left = 0
if len(moves) is 2:
	if moves[0] is 'L' and moves[1] is 'R' or (moves[1] is 'L' and moves[0] is 'R'):
		print('0')
	elif moves[0] is 'U' and moves[1] is 'D' or (moves[1] is 'U' and moves[0] is 'D'):
		print('0')
	else:
		print('1')
elif len(moves) % 2 is not 0:
	print('-1')
else:
	for move in moves:
		if move is 'U':
			up += 1
		elif move is 'D':
			down += 1
		elif move is 'R':
			right += 1
		elif move is 'L':
			left += 1
	min_up_down = 0
	min_left_right = 0
	if up < down:
		min_up_down = down - up
	else:
		min_up_down = up - down
	if right < left:
		min_left_right = left - right
	else:
		min_left_right = right - left
	final_moves = 0
	if min_left_right is 0:
		final_moves = int(min_up_down / 2)
		print(final_moves)
	elif min_up_down is 0:
		final_moves = int(min_left_right / 2)
		print(final_moves)
	elif min_left_right is min_up_down:
		print(min_up_down)
	else:
		print(int((min_left_right + min_up_down) / 2))


big_string = input()
if len(big_string) % 2:
	print(-1)
else:
	lefts = 0
	ups = 0
	downs = 0
	rights = 0
	for letter in big_string:
		if letter == 'L':
			lefts += 1
		elif letter == 'R':
			rights += 1
		elif letter == 'U':
			ups += 1
		else:
			downs += 1
	right_left_dif = abs(lefts - rights)
	up_down_dif = abs(ups - downs)
	print((right_left_dif + up_down_dif) // 2)


s = list(input())
u = d = l = r = 0
for x in s:
	if x == 'R':
		r += 1
	if x == 'U':
		u += 1
	if x == 'L':
		l += 1
	if x == 'D':
		d += 1
ud = abs(u - d)
lr = abs(l - r)
if (ud + lr) % 2:
	print(-1)
elif ud % 2:
	print(ud // 2 + lr // 2 + 1)
else:
	print(ud // 2 + lr // 2)


(r, l, u, d) = (0, 0, 0, 0)
for c in input():
	if c == 'R':
		r += 1
	elif c == 'L':
		l += 1
	elif c == 'U':
		u += 1
	elif c == 'D':
		d += 1
c = abs(r - l) + abs(u - d)
if c % 2 == 0:
	print(c // 2)
else:
	print(-1)


t = input()
t = list(t)
(x, y) = (0, 0)
for i in range(0, len(t)):
	if t[i] == 'U':
		x += 1
	if t[i] == 'D':
		x -= 1
	if t[i] == 'L':
		y += 1
	if t[i] == 'R':
		y -= 1
if x < 0:
	x *= -1
if y < 0:
	y *= -1
if len(t) % 2 != 0:
	print(-1)
else:
	print((x + y) // 2)


s = input().strip()
if len(s) % 2 != 0:
	print(-1)
else:
	d = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for c in s:
		if d.get(c, None) is None:
			d[c] = 1
		else:
			d[c] += 1
	print((abs(d['R'] - d['L']) + abs(d['U'] - d['D'])) // 2)


string = input()
if len(string) % 2 != 0:
	print(-1)
elif string == len(string) * string[0]:
	print(int(len(string) / 2))
else:
	c = list(map(string.count, ['U', 'D', 'R', 'L']))
	v1 = abs(c[0] - c[1])
	v2 = abs(c[2] - c[3])
	if v1 == v2:
		print(v1)
	else:
		ans = int((v1 + v2) / 2)
		print(ans)


st = input()
x = 0
y = 0
for i in st:
	if i == 'U':
		y += 1
	elif i == 'D':
		y -= 1
	elif i == 'R':
		x += 1
	elif i == 'L':
		x -= 1
x = abs(x)
y = abs(y)
if x % 2 == 0 and y % 2 == 1 or (x % 2 == 1 and y % 2 == 0):
	print('-1')
else:
	count = x // 2 + y // 2
	if x % 2 and y % 2:
		count += 1
	print(count)


s = input()
if len(s) % 2 != 0:
	print(-1)
else:
	(r, l, d, u) = (0, 0, 0, 0)
	for i in s:
		if i == 'R':
			r += 1
		if i == 'L':
			l += 1
		if i == 'D':
			d += 1
		if i == 'U':
			u += 1
	h = abs(r - l)
	v = abs(u - d)
	print((v + h) // 2)


s = input()
if len(s) % 2:
	print(-1)
	exit(0)
(l, r, u, d) = (0, 0, 0, 0)
for i in s:
	if i == 'L':
		l += 1
	elif i == 'R':
		r += 1
	elif i == 'U':
		u += 1
	else:
		d += 1
x = abs(r - l)
y = abs(d - u)
print((x + y) // 2)


a = input()
x = abs(a.count('U') - a.count('D'))
x += abs(a.count('R') - a.count('L'))
print([x // 2, -1][x % 2])


s = input()
if len(s) & 1:
	print(-1)
else:
	from collections import Counter
	c = Counter(s)
	(r, l, u, d) = (c.get('R', 0), c.get('L', 0), c.get('U', 0), c.get('D', 0))
	drl = abs(r - l)
	dud = abs(u - d)
	print(drl // 2 + dud // 2 + (drl & 1))


from math import ceil

def main():
	mys = input()
	l = mys.count('L')
	r = mys.count('R')
	u = mys.count('U')
	d = mys.count('D')
	if len(mys) % 2:
		print(-1)
		return
	ans = abs(d - u)
	ans2 = abs(l - r)
	ans3 = min(ans, ans2)
	ans4 = (max(ans, ans2) - ans3) // 2
	print(ans3 + ans4)
main()


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	(x, y) = (0, 0)
	for c in s:
		if c == 'U':
			y += 1
		if c == 'D':
			y -= 1
		if c == 'R':
			x += 1
		if c == 'L':
			x -= 1
	print((abs(x) + abs(y)) // 2)


d_s = {}
d_s['L'] = 0
d_s['R'] = 0
d_s['U'] = 0
d_s['D'] = 0
s = input()
for c in s:
	d_s[c] += 1
if abs(d_s['L'] - d_s['R']) % 2 == abs(d_s['U'] - d_s['D']) % 2:
	print((abs(d_s['L'] - d_s['R']) + abs(d_s['U'] - d_s['D'])) // 2)
else:
	print(-1)


def trident(s):
	vert = 0
	horiz = 0
	for i in range(len(s)):
		if s[i] == 'U':
			vert += 1
		elif s[i] == 'D':
			vert -= 1
		elif s[i] == 'R':
			horiz += 1
		elif s[i] == 'L':
			horiz -= 1
	vert = abs(vert)
	horiz = abs(horiz)
	if vert % 2 == 0 and horiz % 2 == 0:
		print(vert // 2 + horiz // 2)
	elif vert % 2 != 0 and horiz % 2 != 0:
		print((vert + horiz) // 2)
	else:
		print(-1)
s = input()
trident(s)


n = input()
if len(n) % 2 == 1:
	print(-1)
else:
	(f1, f2) = ('', '')
	count = 0
	(L, D, U, R) = (0, 0, 0, 0)
	for i in n:
		if i == 'L':
			L += 1
		elif i == 'D':
			D += 1
		elif i == 'U':
			U += 1
		elif i == 'R':
			R += 1
	t = L - R
	flag = 0
	if t % 2 == 0:
		count += abs(t)
	else:
		count += abs(t) + 1
		flag = 1
	t = abs(U - D) - flag
	count += abs(t)
	print(count // 2)


s = input()
x = abs(s.count('L') - s.count('R'))
y = abs(s.count('U') - s.count('D'))
print(-1 if len(s) & 1 > 0 else x + y >> 1)


h = v = 0
line = str(input())
for it in line:
	if it == 'R':
		h += 1
	elif it == 'L':
		h -= 1
	elif it == 'U':
		v += 1
	elif it == 'D':
		v -= 1
distance = abs(abs(h) - abs(v))
if distance % 2 > 0:
	print(-1)
else:
	print(distance // 2 + min(abs(h), abs(v)))


from collections import Counter
s = input()
if len(s) % 2:
	print(-1)
else:
	c = Counter(s)
	print((abs(c['L'] - c['R']) + abs(c['U'] - c['D'])) // 2)


s = input()
if len(s) % 2:
	print(-1)
else:
	d = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
	for ch in s:
		d[ch] += 1
	d1 = abs(d['U'] - d['D'])
	d2 = abs(d['L'] - d['R'])
	print((d1 + d2) // 2)


s = input()
u = s.count('U')
d = s.count('D')
r = s.count('R')
l = s.count('L')
if len(s) % 2 == 1:
	print(-1)
	exit()
print((abs(u - d) + abs(r - l)) // 2)


s = input()
(x, y) = (0, 0)
for i in s:
	if i == 'R':
		x += 1
	if i == 'L':
		x -= 1
	if i == 'U':
		y += 1
	if i == 'D':
		y -= 1
if x == y == 0:
	print(0)
	quit()
if len(s) % 2:
	print(-1)
	quit()
from math import ceil
(ax, ay) = (abs(x), abs(y))
print(min(ax, ay) + (max(ax, ay) - min(ax, ay)) // 2)


import sys
s = input()
if len(s) % 2 != 0:
	print(-1)
	sys.exit(0)
x = 0
y = 0
for c in s:
	if c == 'L':
		x -= 1
	if c == 'R':
		x += 1
	if c == 'U':
		y += 1
	if c == 'D':
		y -= 1
print((abs(x) + abs(y)) // 2)


s = input()
u = d = l = r = 0
for i in range(len(s)):
	if s[i] == 'U':
		u += 1
	elif s[i] == 'D':
		d += 1
	elif s[i] == 'L':
		l += 1
	else:
		r += 1
t1 = abs(l - r)
t2 = abs(d - u)
if (t1 + t2) % 2 == 0:
	print((t1 + t2) // 2)
else:
	print('-1')


move = input()
if len(move) % 2 != 0:
	print(-1)
else:
	l = move.count('L')
	r = move.count('R')
	u = move.count('U')
	d = move.count('D')
	print((abs(u - d) + abs(l - r)) // 2)


import sys
s = sys.stdin.readline().strip()

def getSteps(s):
	steps = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	for step in s:
		steps[step] += 1
	x = abs(steps['U'] - steps['D'])
	y = abs(steps['R'] - steps['L'])
	if x % 2 == 1 and y % 2 == 1:
		return x // 2 + y // 2 + 1
	elif x % 2 == 1 or y % 2 == 1:
		return -1
	else:
		return x // 2 + y // 2

def doTest():
	assert getSteps('RRU') == -1
	assert getSteps('UDUR') == 1
	assert getSteps('RUUR') == 2
doTest()
print(getSteps(s))


s = input()
if len(s) % 2 == 1:
	print('-1')
	exit(0)
left = 0
right = 0
up = 0
down = 0
for c in s:
	if c == 'L':
		left += 1
	elif c == 'R':
		right += 1
	elif c == 'U':
		up += 1
	else:
		down += 1
x = abs(left - right)
y = abs(up - down)
if x > y:
	print(y + (x - y) // 2)
else:
	print(x + (y - x) // 2)


instr = input()
if len(instr) % 2 != 0:
	print(-1)
else:
	directions = {'R': 0, 'L': 0, 'U': 0, 'D': 0}
	for ins in instr:
		if not ins in directions:
			directions[ins] = 0
		else:
			directions[ins] += 1
	diff = int((abs(directions['R'] - directions['L']) + abs(directions['U'] - directions['D'])) / 2)
	print(diff)


s = input()
l = s.count('L')
r = s.count('R')
u = s.count('U')
d = s.count('D')
num = max(l, r) - min(l, r) + max(u, d) - min(u, d)
if num % 2 == 0:
	print(num // 2)
else:
	print(-1)


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	tmp = min(l, r)
	l -= tmp
	r -= tmp
	tmp = min(u, d)
	d -= tmp
	u -= tmp
	count = 0
	for i in [l, r]:
		if i:
			count += i // 2
			if i % 2:
				count += 1
	for i in [u, d]:
		if i:
			count += i // 2
	print(count)


s = input()
ud = lr = 0
for ch in s:
	if ch == 'R':
		lr = lr + 1
	if ch == 'L':
		lr = lr - 1
	if ch == 'U':
		ud = ud + 1
	if ch == 'D':
		ud = ud - 1
if (abs(lr) + abs(ud)) % 2 == 1:
	print(-1)
else:
	print(int((abs(lr) + abs(ud)) / 2))


s = input()
a = 0
b = 0
for i in range(len(s)):
	if s[i] == 'U':
		a += 1
	if s[i] == 'D':
		a -= 1
	if s[i] == 'R':
		b += 1
	if s[i] == 'L':
		b -= 1
if len(s) % 2 == 1:
	print(-1)
if len(s) % 2 == 0:
	print((abs(a) + abs(b)) // 2)


s = input().strip()
(up, down, left, right) = (0, 0, 0, 0)
if len(s) % 2 != 0:
	print(-1)
else:
	for i in s:
		if i == 'U':
			up += 1
		elif i == 'D':
			down += 1
		elif i == 'L':
			left += 1
		elif i == 'R':
			right += 1
	d1 = abs(up - down)
	d2 = abs(left - right)
	if (d1 + d2) % 2 == 0:
		print((d1 + d2) // 2)
	else:
		print(-1)


t = input
p = print
r = range
a = t()
counter = [0] * 4
for i in a:
	if i == 'L':
		counter[0] += 1
	elif i == 'R':
		counter[1] += 1
	elif i == 'U':
		counter[2] += 1
	else:
		counter[3] += 1
ans = -1
if len(a) & 1 == 0:
	LR = abs(counter[0] - counter[1])
	DU = abs(counter[2] - counter[3])
	ans = (LR + DU) // 2
print(ans)


s = input()
n = len(s)
ans = 0
if n % 2 == 1:
	print('-1')
else:
	p = 0
	q = 0
	for i in range(0, n):
		if s[i] == 'R':
			p += 1
		elif s[i] == 'U':
			q += 1
		elif s[i] == 'L':
			p -= 1
		elif s[i] == 'D':
			q -= 1
	if p % 2 == 0:
		ans = abs(p // 2) + abs(q // 2)
	else:
		ans1 = min(abs(p - 1), abs(p + 1))
		ans2 = min(abs(q - 1), abs(q + 1))
		ans = (ans1 + ans2) // 2 + 1
	print(ans)


def sol(s):
	if len(s) % 2 != 0:
		return -1
	lr = 0
	ud = 0
	for c in s:
		if c == 'L':
			lr -= 1
		elif c == 'R':
			lr += 1
		elif c == 'U':
			ud += 1
		elif c == 'D':
			ud -= 1
	return (abs(lr) + abs(ud)) // 2
s = input()
print(sol(s))


cmd = input()
if len(cmd) % 2 == 1:
	print(-1)
else:
	u = 0
	d = 0
	l = 0
	r = 0
	for c in cmd:
		if c == 'U':
			u += 1
		if c == 'D':
			d += 1
		if c == 'L':
			l += 1
		if c == 'R':
			r += 1
	print(int((abs(u - d) + abs(r - l)) / 2))


line = input()
if len(line) % 2:
	print(-1)
else:
	x = abs(line.count('U') - line.count('D'))
	y = abs(line.count('R') - line.count('L'))
	print((x + y) // 2)


def solve(n):
	if len(n) % 2 != 0:
		return -1
	h = 0
	v = 0
	for j in n:
		if j == 'L':
			h -= 1
		if j == 'R':
			h += 1
		if j == 'D':
			v -= 1
		if j == 'U':
			v += 1
	return (abs(h) + abs(v)) // 2
n = input()
print(solve(n))


s = input()
c = [0] * 4
if len(s) % 2 != 0:
	print('-1')
else:
	for x in range(len(s)):
		if s[x] == 'U':
			c[0] += 1
		elif s[x] == 'D':
			c[1] += 1
		elif s[x] == 'L':
			c[2] += 1
		elif s[x] == 'R':
			c[3] += 1
	[u, l] = [abs(c[0] - c[1]), abs(c[2] - c[3])]
	ans = min([u, l]) + (max([u, l]) - min([u, l])) / 2
	print(int(ans))


from sys import stdin
s = stdin.readline().strip()
if len(s) % 2 != 0:
	print(-1)
	exit(0)
r = 0
u = 0
d = 0
l = 0
for i in s:
	if i == 'R':
		r += 1
	elif i == 'U':
		u += 1
	elif i == 'D':
		d += 1
	else:
		l += 1
ans = 0
if abs(r - l) % 2 != 0:
	if u > d:
		u -= 1
	else:
		d -= 1
	if l > r:
		l -= 1
	else:
		r -= 1
	ans += 1
print(abs(r - l) // 2 + abs(u - d) // 2 + ans)


from math import *
A = input()
b = len(A)
if b % 2 > 0:
	print('-1')
else:
	itoga = list(range(4))
	for i in range(4):
		itoga[i] = 0
	for i in range(b):
		if A[i] == 'U':
			itoga[0] += 1
		if A[i] == 'D':
			itoga[1] += 1
		if A[i] == 'L':
			itoga[2] += 1
		if A[i] == 'R':
			itoga[3] += 1
	zad1 = abs(itoga[0] - itoga[1])
	zad2 = abs(itoga[2] - itoga[3])
	if zad1 != 0 and zad2 != 0:
		if zad1 == zad2:
			print(zad1)
		if zad1 > zad2:
			print(zad2 + int((zad1 - zad2) / 2))
		if zad2 > zad1:
			print(zad1 + int((zad2 - zad1) / 2))
	elif zad1 != 0:
		print(int(zad1 / 2))
	else:
		print(int(zad2 / 2))


s = input()
if len(s) % 2:
	print(-1)
	exit()
v = h = 0
for i in s:
	if i == 'L':
		h -= 1
	elif i == 'R':
		h += 1
	elif i == 'U':
		v += 1
	else:
		v -= 1
print((abs(v) + abs(h)) // 2)


com = input()
up = 0
right = 0
for command in com:
	if command == 'U':
		up += 1
	elif command == 'D':
		up -= 1
	elif command == 'R':
		right += 1
	else:
		right -= 1
total = abs(right) + abs(up)
if total % 2 == 0:
	print(int(total / 2))
else:
	print('-1')


n = input().upper()
a = [0, 0]
l = [i for i in n]
for j in l:
	if j == 'U':
		a[0] += 1
	elif j == 'D':
		a[0] -= 1
	elif j == 'R':
		a[1] += 1
	else:
		a[1] -= 1
if len(n) % 2 != 0:
	print(-1)
else:
	ans = abs(a[0]) + abs(a[1])
	print(int(ans / 2))


s = input()
d1 = 0
d2 = 0
for i in s:
	if i == 'L':
		d1 += 1
	elif i == 'R':
		d1 -= 1
	elif i == 'U':
		d2 += 1
	else:
		d2 -= 1
t = abs(d1) + abs(d2)
if t % 2 != 0:
	print(-1)
else:
	print(t // 2)


S = input()
if len(S) % 2 != 0:
	print(-1)
else:
	d = S.count('R')
	d1 = S.count('U')
	d2 = S.count('L')
	d3 = S.count('D')
	h = d
	h1 = d2
	d2 = max(h, h1)
	d = min(h, h1)
	h = d1
	h1 = d3
	d3 = max(h, h1)
	d1 = min(h, h1)
	k = 0
	if (d + d2) % 2 != 0:
		d2 = d2 - 1
		d1 = d1 + 1
		k = k + 1
	if (d3 + d1) % 2 != 0:
		d3 = d3 - 1
		d = d + 1
		k = k + 1
	print(abs(d - d2) // 2 + abs(d1 - d3) // 2 + k)


from math import *
s = input()
x = len(s)
z = 0
c = 0
for i in range(x):
	if s[i] == 'L':
		c += 1
	if s[i] == 'R':
		c -= 1
	if s[i] == 'U':
		z += 1
	if s[i] == 'D':
		z -= 1
for i in range(1):
	if x % 2 != 0:
		print('-1')
	else:
		c = abs(c) + abs(z)
		c = int(c / 2)
		print(abs(c))


s = str(input())
if len(s) % 2 == 1:
	print(-1)
else:
	u = 0
	d = 0
	r = 0
	l = 0
	while len(s) > 0:
		if s[0] == 'U':
			u += 1
		elif s[0] == 'D':
			d += 1
		elif s[0] == 'R':
			r += 1
		else:
			l += 1
		s = s[1:]
	print(int((abs(u - d) + abs(r - l)) / 2))


s = input()
n = len(s)
if n % 2 != 0:
	print(-1)
else:
	d = {x: 0 for x in 'LRUD'}
	for c in s:
		d[c] += 1
	print((abs(d['R'] - d['L']) + abs(d['U'] - d['D'])) // 2)


path = input()
U = 0
D = 0
L = 0
R = 0
for c in path:
	if c == 'U':
		U += 1
	elif c == 'D':
		D += 1
	elif c == 'L':
		L += 1
	else:
		R += 1
if (U + D + L + R) % 2 == 1:
	print(-1)
	exit()
m = min(U, D)
U -= m
D -= m
m = min(L, R)
L -= m
R -= m
print(int((U + D + L + R) / 2))


S = input()
u = 0
d = 0
r = 0
l = 0
for s in S:
	if s == 'U':
		u += 1
	elif s == 'D':
		d += 1
	elif s == 'R':
		r += 1
	elif s == 'L':
		l += 1
if len(S) % 2 != 0:
	print(-1)
	exit()
ans = 0
ans += abs(u - d) // 2
ans += abs(r - l) // 2
if abs(u - d) % 2 != 0:
	ans += 1
print(ans)


import collections
move = input()
cnt = collections.Counter()
final = 0
if len(move) % 2 == 1:
	print(-1)
else:
	for i in range(len(move)):
		cnt[move[i]] += 1
	print(int(abs(cnt['L'] - cnt['R']) / 2 + abs(cnt['U'] - cnt['D']) / 2))


m = input()
r = 0
l = 0
u = 0
d = 0
for char in m:
	if char == 'R':
		r += 1
	elif char == 'L':
		l += 1
	elif char == 'U':
		u += 1
	elif char == 'D':
		d += 1
if (u + d + r + l) % 2 == 1:
	print(-1)
else:
	ud = abs(u - d)
	rl = abs(r - l)
	print((ud + rl) // 2)


a = input()
num = a.count('L')
num1 = a.count('R')
num2 = a.count('U')
num3 = a.count('D')
lent = len(a)
if lent % 2 == 0:
	dif = num - num1
	dif1 = num2 - num3
	if dif < 0:
		dif = -dif
	if dif1 < 0:
		dif1 = -dif1
	if dif > dif1:
		min1 = dif1
	else:
		min1 = dif
	sub = dif - dif1
	if sub < 0:
		sub = -sub
	ans = min1 + sub // 2
	print(ans)
else:
	print('-1')


import sys
s = input()
if len(s) % 2 != 0:
	print(-1)
	sys.exit()
d = {'R': 0, 'L': 0, 'D': 0, 'U': 0}
for l in s:
	d[l] += 1
non_zero = 0
for (k, v) in d.items():
	if v != 0:
		non_zero += 1
if non_zero == 1:
	print(int(len(s) / 2))
	sys.exit()
if non_zero == 2 and d['R'] != 0 and (d['L'] != 0):
	for (k, v) in d.items():
		if v != 0:
			other = len(s) - v
			if v >= other:
				print(int((v - other) / 2))
				sys.exit()
			else:
				print(int((other - v) / 2))
				sys.exit()
if non_zero == 2 and d['U'] != 0 and (d['D'] != 0):
	for (k, v) in d.items():
		if v != 0:
			other = len(s) - v
			if v >= other:
				print(int((v - other) / 2))
				sys.exit()
			else:
				print(int((other - v) / 2))
				sys.exit()
r = (max(d['R'], d['L']) - min(d['R'], d['L']) + max(d['U'], d['D']) - min(d['U'], d['D'])) / 2
print(int(r))


def STR():
	return list(input())

def INT():
	return int(input())

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

def MAP2():
	return map(float, input().split())

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

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
s = STR()
r = s.count('R')
l = s.count('L')
u = s.count('U')
d = s.count('D')
if r == l and u == d:
	print('0')
	exit(0)
if len(s) % 2 != 0:
	print('-1')
	exit(0)
cnt = 0
x = min(r, l)
r -= x
l -= x
y = min(u, d)
u -= y
d -= y
z = l + r + d + u
cnt += z // 2
print(cnt)


a = input()
u = 0
d = 0
l = 0
r = 0
for i in a:
	if i == 'U':
		u += 1
	elif i == 'D':
		d += 1
	elif i == 'R':
		r += 1
	else:
		l += 1
x = abs(r - l)
y = abs(u - d)
printar = 0
while x > 0 and y > 0:
	printar += 1
	x -= 1
	y -= 1
if x == 0 and y == 0:
	print(printar)
elif x % 2 == 0 and y % 2 == 0:
	printar += x / 2 + y / 2
	print(int(printar))
else:
	print(-1)


s = input()
l = 0
u = 0
if len(s) % 2 == 0:
	for i in range(len(s)):
		if s[i] == 'L':
			l += 1
		if s[i] == 'R':
			l -= 1
		if s[i] == 'U':
			u += 1
		if s[i] == 'D':
			u -= 1
	ans = abs(u) + abs(l)
	print(ans // 2)
else:
	print(-1)


s = input()
a = [0, 0, 0, 0]
for S in s:
	if S == 'U':
		a[0] += 1
	if S == 'R':
		a[1] += 1
	if S == 'D':
		a[2] += 1
	if S == 'L':
		a[3] += 1
if len(s) % 2 == 1:
	print(-1)
else:
	print((abs(a[0] - a[2]) + abs(a[1] - a[3])) // 2)


s = input()
len_s = len(s)
if len_s % 2 == 1:
	print(-1)
	exit()
direction = 'LRUD'
counts = [0] * 4
for i in s:
	counts[direction.index(i)] += 1
left_right = abs(counts[0] - counts[1])
up_down = abs(counts[2] - counts[3])
min = left_right // 2 + up_down // 2
if left_right % 2 == 1:
	min += 1
print(min)


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	d = {'D': 0, 'U': 0, 'L': 0, 'R': 0}
	for i in s:
		d[i] += 1
	print((abs(d['U'] - d['D']) + abs(d['L'] - d['R'])) // 2)


a = input()
x = 0
y = 0
for i in a:
	if i == 'U':
		x += 1
	elif i == 'D':
		x -= 1
	elif i == 'R':
		y += 1
	else:
		y -= 1
x = abs(x)
y = abs(y)
printar = 0
while x > 0 and y > 0:
	printar += 1
	x -= 1
	y -= 1
if x == 0 and y == 0:
	print(printar)
elif x % 2 == 0 and y % 2 == 0:
	printar += x / 2 + y / 2
	print(int(printar))
else:
	print(-1)


(u, r) = (0, 0)
for i in input():
	if i == 'U':
		u += 1
	elif i == 'D':
		u -= 1
	elif i == 'R':
		r += 1
	else:
		r -= 1
if not abs(u) % 2 ^ abs(r) % 2:
	print((abs(u) + abs(r)) // 2)
else:
	print(-1)


s = input()
length = len(s)
(u, d, l, r) = (0, 0, 0, 0)
steps = 0
for i in range(length):
	if s[i] == 'L':
		l += 1
	if s[i] == 'R':
		r += 1
	if s[i] == 'U':
		u += 1
	if s[i] == 'D':
		d += 1
if l >= r:
	steps += l - r
if r > l:
	steps += r - l
if u >= d:
	steps += u - d
if d > u:
	steps += d - u
if length % 2 != 0:
	print(-1)
else:
	print(int(steps / 2))


s = input()
if len(s) % 2 == 1:
	print(-1)
else:
	(u, d, r, l) = (s.count('U'), s.count('D'), s.count('R'), s.count('L'))
	ud = u - d if u - d > 0 else d - u
	rl = r - l if r - l > 0 else l - r
	print((ud + rl) // 2)


L = 0
R = 0
U = 0
D = 0
xs = input()
if len(xs) % 2 == 1:
	print(-1)
else:
	for x in xs:
		if x == 'L':
			L += 1
		elif x == 'R':
			R += 1
		elif x == 'U':
			U += 1
		else:
			D += 1
	x = R - L
	y = U - D
	sol = (abs(x) + abs(y)) // 2
	print(sol)


from collections import defaultdict
s = input()
com = defaultdict(int)
for i in s:
	com[i] += 1
if len(s) % 2:
	print(-1)
else:
	print((abs(com['U'] - com['D']) + abs(com['R'] - com['L'])) // 2)


import collections
import functools
import math
import sys
import bisect

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

def memtri():
	l = [0, 0]
	for i in input().rstrip():
		if i == 'U':
			l[0] += 1
		elif i == 'D':
			l[0] -= 1
		elif i == 'L':
			l[1] -= 1
		else:
			l[1] += 1
	ans = min(abs(l[0]), abs(l[1]))
	for i in range(2):
		if l[i] < 0:
			l[i] += ans
		else:
			l[i] -= ans
	if l[0] % 2 or l[1] % 2:
		return -1
	return abs(l[0] // 2) + abs(l[1] // 2) + ans
print(memtri())


s = input()
C = str.count
a = abs(C(s, 'R') - C(s, 'L')) + abs(C(s, 'U') - C(s, 'D'))
print([-1, a // 2][a % 2 == 0])


(R, L, U, D) = (0, 0, 0, 0)
for c in input():
	if c == 'R':
		R += 1
	elif c == 'L':
		L += 1
	elif c == 'U':
		U += 1
	elif c == 'D':
		D += 1
diff_RL = abs(R - L)
diff_UD = abs(U - D)
if diff_RL % 2 == 0 and diff_UD % 2 == 0 or (diff_RL % 2 == 1 and diff_UD % 2 == 1):
	print((diff_RL + diff_UD) // 2)
else:
	print(-1)


cnt = []
ms = input()
cnt += [ms.count('U')]
cnt += [ms.count('D')]
cnt += [ms.count('R')]
cnt += [ms.count('L')]
ans = abs(cnt[0] - cnt[1]) + abs(cnt[2] - cnt[3])
if ans % 2 == 1:
	print(-1)
else:
	print(ans // 2)


s = str(input())
n = len(s)
x = 0
y = 0
for i in range(0, n):
	if s[i] is 'L':
		x -= 1
	elif s[i] is 'R':
		x += 1
	elif s[i] is 'U':
		y += 1
	else:
		y -= 1
x = abs(x)
y = abs(y)
if (x + y) % 2 is 0:
	print((x + y) // 2)
else:
	print(-1)


s = list(input())
ver = hor = 0
for i in range(len(s)):
	if s[i] == 'U':
		ver += 1
	elif s[i] == 'D':
		ver -= 1
	elif s[i] == 'L':
		hor += 1
	else:
		hor -= 1
if (abs(ver) + abs(hor)) % 2 != 0:
	print(-1)
else:
	ans = (abs(ver) + abs(hor)) // 2
	print(ans)


def main():
	s = input()
	if len(s) % 2 == 1:
		print('-1')
		return
	cnt = {'L': 0, 'R': 0, 'U': 0, 'D': 0}
	for c in s:
		cnt[c] += 1
	reduce1 = abs(cnt['L'] - cnt['R'])
	reduce2 = abs(cnt['U'] - cnt['D'])
	print((reduce1 + reduce2) // 2)
main()


import math
n = input()
if len(n) % 2 == 1:
	print(-1)
	exit(0)
(x, y) = (0, 0)
for i in n:
	if i == 'R':
		y += 1
	if i == 'U':
		x += 1
	if i == 'D':
		x -= 1
	if i == 'L':
		y -= 1
x = math.fabs(x)
y = math.fabs(y)
s = x + y
s = math.fabs(s)
s = int(s)
if s > 1:
	s //= 2
elif s != 0:
	s = 1
print(s)


A = input()
AL = []
for a in A:
	AL.append(a)
L = AL.count('L')
R = AL.count('R')
D = AL.count('D')
U = AL.count('U')
if len(A) % 2 == 1:
	print('-1')
elif L == R and D == U:
	print('0')
else:
	if D > U:
		x = D - U
	else:
		x = U - D
	if L > R:
		y = L - R
	else:
		y = R - L
	print(int((x + y) / 2))


s = input()
(l, r, u, d) = (s.count('l'), s.count('r'), s.count('u'), s.count('d'))
(x, y) = (s.count('L') - s.count('R'), s.count('U') - s.count('D'))
r = abs(x) // 2 + abs(y) // 2
if abs(x) % 2 == abs(y) % 2 == 0:
	print(r)
elif abs(x) % 2 == abs(y) % 2 == 1:
	print(r + 1)
else:
	print('-1')


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
s = input()
d = dict.fromkeys('DLRU', 0)
t = 0
for c in s:
	d[c] += 1
if sum(d.values()) & 1:
	print(-1)
else:
	print((abs(d['U'] - d['D']) + abs(d['R'] - d['L'])) // 2)


t = input()
R = 0
L = 0
U = 0
D = 0
if len(t) % 2 == 0:
	for letters in t:
		if letters == 'R':
			R += 1
		elif letters == 'L':
			L += 1
		elif letters == 'U':
			U += 1
		elif letters == 'D':
			D += 1
	lados = R - L
	arriba = U - D
	if lados < 0:
		lados = -lados
	if arriba < 0:
		arriba = -arriba
	if lados == arriba:
		print(lados)
	elif lados % 2 == 0 and arriba % 2 == 0:
		print((lados + arriba) // 2)
	elif lados % 2 != 0 or arriba % 2 != 0:
		print((lados + arriba) // 2)
else:
	print(-1)


s = input()
l = [0] * 2
for el in s:
	if el == 'L':
		l[0] += 1
	if el == 'R':
		l[0] -= 1
	if el == 'U':
		l[1] += 1
	if el == 'D':
		l[1] -= 1
l[0] = abs(l[0])
l[1] = abs(l[1])
if sum(l) % 2 != 0:
	print(-1)
else:
	print(sum(l) // 2)


s = input()
n = len(s)
if n % 2 != 0:
	print('-1')
	exit(0)
x = 0
y = 0
for i in range(n):
	if s[i] == 'U':
		y += 1
	elif s[i] == 'R':
		x += 1
	elif s[i] == 'D':
		y -= 1
	elif s[i] == 'L':
		x -= 1
d = abs(x) + abs(y)
print(int(d / 2))


s = str(input())
n = len(s)
if n % 2 == 1:
	print(-1)
else:
	l = s.count('L')
	r = s.count('R')
	u = s.count('U')
	d = s.count('D')
	if l == r:
		print(abs(u - d) // 2)
	elif u == d:
		print(abs(l - r) // 2)
	elif (l - r) % 2 == 0 and (u - d) % 2 == 0:
		print(abs(l - r) // 2 + abs(u - d) // 2)
	else:
		print(1 + abs(l - r) // 2 + abs(u - d) // 2)


s = input()
if len(s) % 2 == 1:
	print(-1)
	exit()
left_right = abs(s.count('L') - s.count('R'))
up_down = abs(s.count('U') - s.count('D'))
min = left_right // 2 + up_down // 2
if left_right % 2 == 1:
	min += 1
print(min)


def mover(pos, mov):
	if mov == 'L':
		pos[0] += 1
	elif mov == 'R':
		pos[0] -= 1
	elif mov == 'U':
		pos[1] += 1
	else:
		pos[1] -= 1
movimientos = list(input())
posicion = [0, 0]
for i in movimientos:
	mover(posicion, i)
movimientos_malos = abs(posicion[0]) + abs(posicion[1])
if movimientos_malos % 2 == 0:
	print(abs(movimientos_malos // 2))
else:
	print(-1)


s = input()
n = len(s)
if len(s) % 2:
	print('-1')
	exit()
a = abs(s.count('L') - s.count('R'))
b = abs(s.count('U') - s.count('D'))
print(min(a, b) + int(abs(a - b) // 2))


from sys import stdin, stdout

def get_position(dic):
	return (dic['R'] - dic['L'], dic['U'] - dic['D'])

def foo(raw_line):
	line = raw_line.strip()
	out = 0
	dic = {'U': 0, 'D': 0, 'R': 0, 'L': 0}
	if len(line) % 2 == 1:
		return -1
	for i in line:
		dic[i] += 1
	(x, y) = get_position(dic)
	return (abs(x) + abs(y)) // 2

def main():
	print(foo(stdin.readline()))
main()


import math
import sys
a = input()
cud = 0
clr = 0
for i in range(len(a)):
	if a[i] == 'L':
		clr -= 1
	if a[i] == 'R':
		clr += 1
	if a[i] == 'U':
		cud += 1
	if a[i] == 'D':
		cud -= 1
if (cud - clr) % 2 == 0:
	print(int((abs(cud) + abs(clr)) / 2))
	sys.exit()
print(-1)


from math import *

def co(s, c):
	t = 0
	for i in s:
		if c == i:
			t += 1
	return t
s = input()
if len(s) % 2:
	print(-1)
else:
	a = co(s, 'D')
	b = co(s, 'U')
	c = co(s, 'R')
	d = co(s, 'L')
	if (a - b) % 2:
		print(int(fabs(a - b) // 2 + fabs(c - d) // 2 + 1))
	else:
		print(int(fabs(a - b) // 2 + fabs(c - d) // 2))