#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <time.h>
using namespace std;
const double eps=1e-6;
#define fr first
#define sc second
#define mp make_pair
const double pi=3.1415926535897932384626433832795;
const int inf=3e6;
int luck(int x)
{
    int k=0;
    char s[15];
    itoa(x,s,10);
    for (int i=0;i<strlen(s);i++)
        if (s[i]=='4'||s[i]=='7')k++;
    return k;
}
int main()
{
   freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  int n,k,ans=0;
  scanf("%d%d\n",&n,&k);
  for (int i=0;i<n;i++)
  {
   int x;
   scanf("%d",&x);
   if (luck(x)<=k)ans++;
  }
  printf("%d",ans);
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <time.h>
using namespace std;
const double eps=1e-6;
#define fr first
#define sc second
#define mp make_pair
const double pi=3.1415926535897932384626433832795;
const int inf=3e6;
int luck(int x)
{
    int k=0;
    char s[15];
    itoa(x,s,10);
    for (int i=0;i<strlen(s);i++)
        if (s[i]=='4'||s[i]=='7')k++;
    return k;
}
int main()
{
  // freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
  int n,k,ans=0;
  scanf("%d%d\n",&n,&k);
  for (int i=0;i<n;i++)
  {
   int x;
   scanf("%d",&x);
   if (luck(x)<=k)ans++;
  }
  printf("%d",ans);
}


#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int * a = new int[n];

	for (int i = 0; i < n; ++i)
		cin >> a[i];

	int answ = 0;

	for (int i = 0; i < n; ++i){
		int count = 0;
		bool f = 0;
		while (a[i]){
			if (a[i] % 10 == 4 || a[i] % 10 == 7){
				f = 1;
				++count;
			}
			else {
				if (f)
					break;

			}
				a[i] = a[i] / 10;
		}
		if (f == 0 && !a[i] || f == 1 && count <= k)
			++answ;
	}
	cout << answ;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int * a = new int[n];

	for (int i = 0; i < n; ++i)
		cin >> a[i];

	int answ = 0;

	for (int i = 0; i < n; ++i){
		int count = 0;
		while (a[i]){
			if (a[i] % 10 == 4 || a[i] % 10 == 7)
				++count;
			a[i] = a[i] / 10;
		}
		if (count <= k)
			++answ;
	}
	cout << answ;
	return 0;
}


#include <iostream>
using namespace std;

int  main()
{
	int n, k;
	cin >> n >> k;
	int * a = new int[n];

	for (int i = 0; i < n; ++i)
		cin >> a[i];

	int answ = 0;

	for (int i = 0; i < n; ++i){
		int count = 0;
		bool f = 0;
		while (a[i]){
			if (a[i] % 10 == 4 || a[i] % 10 == 7){
				f = 1;
				++count;
			}
			else {
				if (f)
					break;

			}
			a[i] = a[i] / 10;
		}
		if (!a[i] && count < ++k)
			++answ;
	}
	cout << answ;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int * a = new int[n];

	for (int i = 0; i < n; ++i)
		cin >> a[i];

	int answ = 0;

	for (int i = 0; i < n; ++i){
		int count = 0;
		bool f = 0;
		if (a[i] % 10 == 4 || a[i] % 10 == 7)
			f = 1;
		while (a[i]){
			if (f){
				if (a[i] % 10 == 4 || a[i] % 10 == 7)
					++count;
				else
					break;
			}
			else {
				if (a[i] % 10 == 4 || a[i] % 10 == 7)
					break;
			}
			a[i] = a[i] / 10;
		}
		if (f == 0 && !a[i] || f == 1 && count <= k)
			++answ;
	}
	cout << answ;
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int n, k, ans, cur, t;

int main() {
	sIO();
	scanf("%d%d", &n, &k);
	ans = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &cur);
		t = 0;
		while (cur) {
			++t;
			cur /= 10;
		}
		ans += t <= k;
	}
	printf("%d", ans);
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int n, k, ans, cur, t;

int main() {
	sIO();
	scanf("%d%d", &n, &k);
	ans = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &cur);
		t = 0;
		while (cur) {
			t += cur % 10 == 4 || cur % 10 == 7;
			cur /= 10;
		}
		ans += t <= k;
	}
	printf("%d", ans);
	return 0;
}


#include <iostream>

int main()
{
    unsigned maxHappy(0);
    unsigned curHappy(0);
    unsigned answear(0);
    unsigned short count(0);
    std::cin >> count;
    std::cin >> maxHappy;
    std::cin;
    for (unsigned short i = 0; i < count; ++i)
    {
        char c;
        while (std::cin.get(c) && c != ' ')
        if (c == '4' || c == '7')
            ++curHappy;
        if (curHappy <= maxHappy)
            ++answear;
        curHappy = 0;
    }
    std::cout << answear;
    return 0;
}


#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned maxHappy(0);
    unsigned curHappy(0);
    unsigned answear(0);
    unsigned short count(0);
    std::cin >> count;
    std::cin >> maxHappy;
    std::cin;
    for (unsigned short i = 0; i < count; ++i)
    {
        char c;
        while (std::cin.get(c) && c != ' ')
        if (c == '4' || c == '7')
            ++curHappy;
        if (curHappy <= maxHappy)
            ++answear;
        curHappy = 0;
    }
    std::cout << answear;
    return 0;
}


#include <iostream>

int main()
{
    unsigned maxHappy(0);
    unsigned curHappy(0);
    unsigned answear(0);
    unsigned short count(0);
    std::cin >> count;
    std::cin >> maxHappy;
    std::cin;
    for (unsigned short i = 0; i < count; ++i)
    {
        char c;
        while (std::cin.get(c) && c != ' ')
        if (c == '4' || c == '7')
            ++curHappy;
        if (curHappy < maxHappy)
            ++answear;
        curHappy = 0;
    }
    std::cout << answear;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, k;
	while( cin >> n >> k ){
		int ans = 0;
		for( int i = 0; i < n; ++i ){
			int a;
			cin >> a;
			int cnt = 0;
			++ans;
			while( a > 0 ){
				int b = a % 10;
				if( b == 4 || b == 7 ) ++cnt;
				if( cnt > k ){
					--ans;
					break;
				}
				a /= 10;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, k;
	while( cin >> n >> k ){
		int ans = 0;
		if( k > 9 ){
			ans = n;
		}else{
			int limit = 7;
			for( int i = 1; i < k; ++i ){
				limit *= 10;
				limit += 7;
			}
			for( int i = 0; i < n; ++i ){
				int a;
				cin >> a;
				if( a <= limit ){
					++ans;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}


n,k=map(int,input().split())
a=list(map(input().split()))
c=0
for i in a:
    if i.count('4')+i.count('7')<=k:
        c+=1
print(c)


n,k=map(int,input().split())
aa=input()
aa=aa.split()
a=[]
for i in aa:
    a.append(i)
c=0
for i in a:
    if i.count('4')+i.count('7')<=k:
        c+=1
print(c)


n,k=map(int,input().split())
l=list(map(int,input().split()))
c1=0
for i in range(n):
    t=l[i]
    c=0
    while(t>0):
        if(t%10==4 or t%10==7):
            c+=1
        t=t//10
    if(c<=k):
        c1+=1
print(c1)


n,k=map(int,input().split())
a=list(input().split())
count=int(0)
for i in a:
    if(i.count('4')+i.count('7')<=k):
        count+=1
print(count)


n,k=map(int,input().split())
a=list(input().split())
count=int(0)
for i in a:
    if(len(i)<=k):
        count+=1
print(count)


a,b = map(int,input().split())
print(sum(i.count('4') + i.count('7') <= b for i in input().split()))


a,b = map(int,input().split())
list1 = input().split()
set1 = set([i for i in range(len(list1)) if len(list1[i]) == list1[i].count('7')+list1[i].count('4')])
print((b-len(set1),b )[len(set1)>b])


k=int(input().split()[1])
count1=0
for i in input().split():
    if i.count('4')+i.count('7')<=k:
        count1+=1
print(count1)


n,k=map(int,input().split())
a=input().split()
count=0
for i in range(n):
    x=a.count('4')+a.count('7')
    if x<=k:
        count+=1
print(count)


n,k=map(int,input().split())
a=list(map(int,input().split()))
no=0
for x in range(n):
    count=0
    while a[x]>0:
        if a[x]%10==4 or a[x]%10==7:
            count+=1
        a[x]=int(a[x]/10)
    if count<=k:
        no+=1
print(no)


n,k=map(int,input().split())
a=list(map(int,input().split()))
no=0
for x in range(n):
    count=0
    while a[x]>0:
        if a[x]%10==4 or a[x]%10==7:
            count+=1
            a[x]=int(a[x]/10)
    if count<=k:
        no+=1
print(no)


n,k=map(int,input().split())
a=list(map(int,input().split()))
no=0
for x in range(n):
    count=0
    if a[x]%10==4 or a[x]%10==7:
        count+=1
        a[x]/10
    if count<=k:
        no+=1
print(no)


n, k = map(int, input().split())
a = list(map(str, input().split()))
c = 0
cnt = 0
for i in range(len(a)):
    a[i] = list(a[i])
    c = c + a[i].count('4') + a[i].count('7')
    if c <= k:
        cnt = cnt + 1
    c = 0
print(cnt)


n, k = map(int, input().split())
a = list(map(str, input().split()))
c = 0
cnt = 0
for i in range(len(a)):
    a[i] = list(a[i])
    c = c + a[i].count('4') + a[i].count('7')
    if c < k:
        cnt = cnt + 1
print(cnt)


n,k=map(int,input().split())
a=list(input().split())
d=[]
for i in a:
    d1=i.count('4')
    d1+=i.count('7')
    d.append(d1)
d.sort()
i=n
while(d[i-1]>k and i>0):
    i-=1
print(i)


n,k=map(int,input().split())
a=list(input().split())
d=[]
for i in a:
    d1=i.count('4')
    d1+=i.count('7')
    d.append(d1)
d.sort()
i=n
while(d[i-1]>k):
    i-=1
print(i)


x,y=map(int,input().split());a=0
c=list(input().split())
for i in range(len(c)) :
    b=list(c[i])
    z=b.count("4")+b.count("7")
    if z<=y :
        a+=1
print(a)


x,y=map(int,input().split());z=0
c=list(input().split())
for i in range(len(c)) :
    b=list(c[i])
    if len(b)<=y :
        z+=1
print(z)


def getLuckyDigits(n):
    luckyDigits: int = 0
    luckyNums = [4,7]
    while n > 0:
        if int(n%10) in luckyNums:
           luckyDigits += 1
        n = int(n / 10)

    return luckyDigits

def getDigits(num):
    return len(str(num))

arr = input().split(" ")
n = int(arr[0])
k = int(arr[1])
count = 0

nums = input().split(" ")

for i in range(n):
    currentNumber = int(nums[i])
    if getLuckyDigits(currentNumber) <= k:
        count+=1

print(count)


def isLucky(n):
    luckyNums = [4,7]
    if n in luckyNums:
        return True
    while n > 0:
        if int(n/10) not in luckyNums or int(n%10) not in luckyNums:
            if (n/10) > 10:
                n/=10
            else:
                return False
        else:
            return True

def getDigits(num):
    return len(str(num))

arr = input().split(" ")
n = int(arr[0])
k = int(arr[1])
count = 0

nums = input().split(" ")

for i in range(n):
    nums[i] = int(nums[i])
    if isLucky(nums[i]) and getDigits(nums[i]) <= k:
        count += 1

print(count)


n, m = map (int, input().split())
a = list(map(str, input().split()))
counter = len(a)
for item in a:
     if item.count('7') + item.count('4') > m:
          counter -= 1
print(counter)


n, k = map(int, input().split())
a = list(map(str, input().split()))
sum = 0
for i in a:
	if a.count('4')+a.count('7') <= k:
		sum += 1
print(sum)


n, k = map(int, input().split())
a = list(map(str, input().split()))
sum = 0
for i in a:
	if i.count('4')+i.count('7') <= k:
		sum += 1
print(sum)


n,k=map(int,input().split())
l=input().split()
list1=["4","7"]
sum1=0
for i in l:
	count=0
	for j in range(len(i)):
		if i[j] in list1:
			count+=1
	if count<=k:
		sum1+=1
print(sum1)


n, l = map(int, input().split())

a = 0

for i in input().split():
    if i.count('4') + i.count('7') <= l:
        a += 1
print(a)


n, l = map(int, input().split())

a = 0

for i in input().split():
    if i.count('4') + i.count('7') < l:
        a += 1
print(a)


n, k = list(map(int, input().split()))
data = list(map(int, input().split()))
ans = 0
for item in data:
	tmp = 0
	for elem in str(item):
		if elem == '2' or elem == '4':
			tmp += 1
	if tmp <= k:
		ans += 1
print(ans)


n, k = list(map(int, input().split()))
data = list(map(int, input().split()))
ans = 0
for item in data:
	tmp = 0
	for elem in str(item):
		if elem == '7' or elem == '4':
			tmp += 1
	if tmp <= k:
		ans += 1
print(ans)


n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
for i in x:
    if str(i).count("4")<=k or str(i).count("7")<=k or str(i).count("4")+str(i).count("7")<=k:
        ans+=1
print(ans)


n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
for i in x:
    if len(str(i))<=k:
        ans+=1
print(ans)


n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
for i in x:
    if str(i).count("4")<=k and str(i).count("7")<=k and str(i).count("4")+str(i).count("7")<=k:
        ans+=1
print(ans)


n,m=map(int,input().split())
l=list(map(str,input().split()))
ans=0
for i in range(n):
    if len(l[i])<=m:
        ans+=1
print(ans)


n,m=map(int,input().split())
l=list(map(str,input().split()))
ans=0
for i in range(n):
    if len(l[i])==m:
        ans+=1
print(ans)


n,m=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for i in l:
    d=0
    for j in str(i):
        if j=='4' or j=='7':d+=1
    if d<=m:ans+=1
print(ans)


a,b = map(int,input().split())
print(sum(i.count('4') + i.count('7') <= b for i in input().split()))


k = int(input().split(' ')[1])
nums = input().split()

print(len(list(filter(lambda x: x.count('4') + x.count('7') <= k, nums))))


k = int(input().split(' ')[1])
nums = input().split()

print(len(list(filter(lambda x: 1 if x.count('4') + x.count('7') <= k else 0, nums))))


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int x = 0, y = 0, L = 0, R = 0, U = 0, D = 0;
    fori(n)
    {
        if (s[i] == 'U') {y++; U++;}
        if (s[i] == 'D') {y--; D++;}
        if (s[i] == 'R') {x++; R++;}
        if (s[i] == 'L') {x--; L++;}
    }
    if (L > R * 2 + U + D || R > L * 2 + U + D || U > D * 2 + L + R || D > U * 2 + R + L) cout << -1;
    else cout << max(L, R) / 2 + max(U, D) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n % 2) {cout << -1; return 0;}
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    cout << (abs(x) + abs(y) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n == 1 || n == 3) {cout << -1; return 0;}
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    cout << (x + 1) / 2 + (y + 1) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n % 2) {cout << -1; return 0;}
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    cout << (x + y) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n == 1 || n == 3) {cout << -1; return 0;}
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    cout << (x + y + 1) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int x = 0, y = 0, L = 0, R = 0, U = 0, D = 0;
    fori(n)
    {
        if (s[i] == 'U') {y++; U++;}
        if (s[i] == 'D') {y--; D++;}
        if (s[i] == 'R') {x++; R++;}
        if (s[i] == 'L') {x--; L++;}
    }
    if (L > R * 2 + U + D || R > L * 2 + U + D || U > D * 2 + L + R || D > U * 2 + R + L) cout << -1;
    else cout << (abs(L - R) + abs(U - D)) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    if ((x % 2) ^ (y % 2)) cout << -1;
    else cout << (x + y) / 2;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n % 2) {cout << -1; return 0;}
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    cout << min(x, y);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pause system("pause")
#define pow(x, n) (ll)pow(1.0 * (x), n)
#define sqrt(x) sqrt(1.0 * (x))
#define pb push_back
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define fork(n) for (int k = 0; k < n; k++)
#define forstarti(start, finish) for (int i = start; i < finish; i++)
#define forstartj(start, finish) for (int j = start; j < finish; j++)
#define IMPOS "IMPOSIBLE"
#define YES "Yes"
#define NO "No"
#define NS "No solution"
#define pl pop_left
#define pr pop_right
#define mp make_pair
#define PI 3.1415926535
#define _f first
#define _s second
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (n % 2) {cout << -1; return 0;}
    int x = 0, y = 0;
    fori(n)
    {
        if (s[i] == 'U') y++;
        if (s[i] == 'D') y--;
        if (s[i] == 'R') x++;
        if (s[i] == 'L') x--;
    }
    cout << (abs(x) + abs(y)) / 2;
    return 0;
}


//Siberian Squirrel
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define print(x) printf("%d\n", x)
typedef long long ll;
const double PI = acos(-1);
const int inf = 0x3f3f3f3f, MAXN = 100100, MOD = 998244353;
inline int read() {
    int res = 0;
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) res = (res << 1) + (res << 3) + (c ^ 48), c = getchar();
    return res;
}
//
int T, k, n, m;
char a[101][101];
int mm[101];
char s[100010];
//
inline ll quick_pow(ll ans, ll p, ll res = 1){
    for(; p; p >>= 1, ans = ans * ans % MOD) {
        if(p & 1) res = res * ans % MOD;
    } return res % MOD;
}
int main(){
    cin >> s; int len = strlen(s);
    if(len & 1) cout << "-1" << endl;
    else {
        int ans = 0;
        int x = 0, y = 0;
        for(int i = 0 ; i < len; ++i) {
            if(s[i] == 'R') x++;
            else if(s[i] == 'L') x--;
            else if(s[i] == 'U') y++;
            else if(s[i] == 'D') y--;
        }
        cout << (abs(x) + abs(y)) / 2 << endl;
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
char s;
int R,L,U,D;
int main()
{
	while(cin >> s)
	{
		if(s == 'R')R ++;
		if(s == 'L')L ++;
		if(s == 'U')U ++;
		if(s == 'D')D ++;
	}
	if(abs(R - L)!=abs(U - D))puts("-1");
	else printf("%d",abs(U - D));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	int x=0,y=0;
	cin>>a;
	int len=a.size();
	if(len%2==1)
	{
		cout<<-1;
		return 0;
	}
	for(int i=0;i<len;i++)
	{
		if(a[i]=='R')x++;
		else if(a[i]=='L')x--;
		else if(a[i]=='U')y++;
		else if(a[i]=='D')y--;
	}
	if(x<0)x=-x;
	if(y<0)y=-y;
	cout<<(x+y)/2;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int chui,heng,ans;
int main()
{
	cin>>s;
	for (int i=0;i<s.length();i++)
	{
		if (s[i]=='L') heng--;
		if (s[i]=='R') heng++;
		if (s[i]=='U') chui++;
		if (s[i]=='D') chui--;
	}
	if (s.length()%2==1) cout<<-1<<endl;
	else
	{
		//cout<<heng<<endl;
		if (abs(heng)%2==1)
		{
			ans++;
			ans+=abs(heng/2)+abs(chui/2);
		}
		else ans=abs(heng/2)+abs(chui/2);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char a;
int x,y,n;
int main()
{
	while(cin>>a)
	{
		n++;
		if(a=='U')y++;
		if(a=='D')y--;
		if(a=='R')x++;
		if(a=='L')x--;
	}
	if(n%2==1)
	{
		cout<<"-1";
		return 0;
	}
	else
	{
		cout<<(abs(x)+abs(y))/2;
		return 0;
	}
	return 0;
}


#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AK>void r(AK &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
string s;
int a,b,c,d;
int main(){
	cin>>s;
	if(s.size()&1){
		puts("-1");
		return 0;
	}
	for(int i=0;s[i];i++){
		if(s[i]=='R')a++;
        if(s[i]=='L')b++;
        if(s[i]=='U')c++;
        if(s[i]=='D')d++;
	}
	printf("%lld\n",((ll)abs(a-b)+(ll)abs(c-d))/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    int n = str.size();
    if(n%2==1){
        cout<<-1;
        return 0;
    }
    int  a = 0;
    for(int i = 0;i<n;i=i+4){
        int l = 0,r = 0,u= 0,d = 0;
        for(int j = i;j<i+4 and j<n;j++){
            //cout<<i<<" "<<j<<endl;
            if(str[j]=='R')
                r++;
            else if(str[j]=='L')
                l++;
            else if(str[j]=='U')
                u++;
            else if(str[j]=='D')
                d++;
        }
        if(r==2)
            a++;
        if(l==2)
            a++;
        if(u==2)
            a++;
        if(d==2)
            a++;
    }
    if(n%4==2){
        if(str[n-1]==str[n-2])
            a++;
    }
    cout<<a;
    //cout<<r<<endl<<l<<endl<<u<<endl<<d;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    int n = str.size();
    if(n%2==1){
        cout<<-1;
        return 0;
    }
    int  a = 0;

    int l = 0,r = 0,u= 0,d = 0;
    for(int j = 0;j<n;j++){
        if(str[j]=='R')
            r++;
        else if(str[j]=='L')
            l++;
        else if(str[j]=='U')
            u++;
        else if(str[j]=='D')
            d++;
    }
    int dif1 = abs(l-r),dif2 = abs(u-d);

    cout<<(dif1+dif2)/2;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    int n = str.size();
    if(n%2==1){
        cout<<-1;
        return 0;
    }
    int  a = 0;

    int l = 0,r = 0,u= 0,d = 0;
    for(int j = 0;j<n;j++){
        if(str[j]=='R')
            r++;
        else if(str[j]=='L')
            l++;
        else if(str[j]=='U')
            u++;
        else if(str[j]=='D')
            d++;
    }
    int dif1 = abs(l-r),dif2 = abs(u-d);
    if (dif1 ==0 and dif2!=0)
        a = dif2/2;
    else if (dif2 == 0 and dif1!=0)
        a = dif1/2;
    else if(dif2 == dif1)
        a = dif1;
    else
        a = abs(dif1 - dif2);
    cout<<a;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    cin>>str;
    int n = str.size();
    if(n%2==1){
        cout<<-1;
        return 0;
    }
    int  a = 0;
    for(int i = 0;i<n;i=i+4){
        int l = 0,r = 0,u= 0,d = 0;
        for(int j = i;j<i+4 and j<n;j++){
            //cout<<i<<" "<<j<<endl;
            if(str[j]=='R')
                r++;
            else if(str[j]=='L')
                l++;
            else if(str[j]=='U')
                u++;
            else if(str[j]=='D')
                d++;
        }
        if(r==2)
            a++;
        if(l==2)
            a++;
        if(u==2)
            a++;
        if(d==2)
            a++;
    }
    if(n%4==2)
        a++;
    cout<<a;
    //cout<<r<<endl<<l<<endl<<u<<endl<<d;

}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	string s;
	cin>>s;

	int x = 0 , y = 0;

	for(int i=0;i<s.size();i++){
		if(s[i]=='U')
			y++;
		else if(s[i]=='D')
			y--;
		else if(s[i]=='L')
			x--;
		else
			x++;
	}
	int counter = 0 ;
	int originalx = x;
	int originaly = y;
	while(x!=0){
		if(originalx<0)
		{
			if(x>0)
				break;
		}
		if(originalx>0)
		{
			if(x<0)
				break;
		}
		if(x<0)
			x+=2;
		else if(x>0)
			x-=2;

		counter++;

	}
	while(y!=0){
		if(originaly<0)
		{
			if(y>0)
				break;
		}
		if(originaly>0)
		{
			if(y<0)
				break;
		}
		if(y<0)
			y+=2;
		else if(y>0)
			y-=2;

		counter++;
	}
	if(((x==1)&&(y==1))||((x==1)&&(y==-1))||((x==-1)&&(y==1))||((x==-1)&&(y==-1)))
		cout<<++counter<<endl;
	else if(counter==s.size()||(x!=0||y!=0))
		cout<<"-1"<<endl;
	else
		cout<<counter<<endl;
}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	int x = 0;
	int y = 0;
	int counter = 0;

	string game;cin>>game;
	for(int i=0;i<game.size();i++){
		if(game[i]=='U')y++;
		else if(game[i]=='D')y--;
		else if(game[i]=='R')x++;
		else x--;
	}

	if((abs(x)+abs(y))%2==1)cout<<-1<<endl;
	else{
		if(x>0){
			while(x>0&&x!=1){
				counter++;
				x-=2;
			}
		}else if(x<0&&x!=-1){
			while(x<0){
				counter++;
				x+=2;
			}
		}
		if(y>0){
			while(y>0&&y!=1){
				counter++;
				y-=2;
			}
		}else if(y<0&&y!=-1){
			while(y<0){
				counter++;
				y+=2;
			}
		}
		if(abs(x)==abs(y))counter+=abs(x);
		cout<<counter<<endl;
	}
}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	int x = 0;
	int y = 0;
	int counter = 0;

	string game;cin>>game;
	for(int i=0;i<game.size();i++){
		if(game[i]=='U')y++;
		else if(game[i]=='D')y--;
		else if(game[i]=='R')x++;
		else x--;
	}
	if(game.size()%2==1){
		cout<<-1<<endl;
		return 0;
	}
	if(x<0)
		x*=-1;
	if(y<0)
		y*=-1;

	while(x>=1){
		x-=2;
		counter++;
	}while(y>=1){
		y-=2;
		counter++;
	}
	if(x==0&&y==0){
		cout<<counter<<endl;
		return 0;
	}else{
		cout<<++counter<<endl;
	}
}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	int x = 0;
	int y = 0;
	int counter = 0;

	string game;cin>>game;
	for(int i=0;i<game.size();i++){
		if(game[i]=='U')y++;
		else if(game[i]=='D')y--;
		else if(game[i]=='R')x++;
		else x--;
	}
	if(game.size()%2==1){
		cout<<-1<<endl;
		return 0;
	}
	if(x<0)
		x*=-1;
	if(y<0)
		y*=-1;

	while(x>1){
		x-=2;
		counter++;
	}while(y>1){
		y-=2;
		counter++;
	}
	if(x==0&&y==0){
		cout<<counter<<endl;
		return 0;
	}else{
		cout<<++counter<<endl;
	}
}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	string s;
	cin>>s;

	int x = 0 , y = 0;

	for(int i=0;i<s.size();i++){
		if(s[i]=='U')
			y++;
		else if(s[i]=='D')
			y--;
		else if(s[i]=='L')
			x--;
		else
			x++;
	}
	int counter = 0 ;
	int originalx = x;
	int originaly = y;
	while(x!=0){
		if(originalx<0)
		{
			if(x>0)
				break;
		}
		if(originalx>0)
		{
			if(x<0)
				break;
		}
		if(x<0)
			x+=2;
		else if(x>0)
			x-=2;

		counter++;

	}
	while(y!=0){
		if(originaly<0)
		{
			if(y>0)
				break;
		}
		if(originaly>0)
		{
			if(y<0)
				break;
		}
		if(y<0)
			y+=2;
		else if(y>0)
			y-=2;

		counter++;
	}
	if(counter==s.size()||(x!=0||y!=0))
		cout<<"-1"<<endl;
	else
		cout<<counter<<endl;
}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
#include<algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	int x = 0;
	int y = 0;
	int counter = 0;

	string game;cin>>game;
	for(int i=0;i<game.size();i++){
		if(game[i]=='U')y++;
		else if(game[i]=='D')y--;
		else if(game[i]=='R')x++;
		else x--;
	}
	if(game.size()%2==1){
		cout<<-1<<endl;
		return 0;
	}
	if(x<0)
		x*=-1;
	if(y<0)
		y*=-1;

	while(x!=1){
		x-=2;
		counter++;
	}while(y!=1){
		y-=2;
		counter++;
	}
		cout<<++counter<<endl;
}


#include <iostream>
#include <cmath>
#include <math.h>
#include<string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void sortSmall(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]>arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
void sortBig(int arr[],int size){
	while(size--){
		for(int i=0;i<size;i++){
			if(arr[i]<arr[i+1]){
				int temp = arr[i];
				arr[i]=arr[i+1];
				arr[i+1]=temp;
			}
		}
	}
}
int min(int arr[],int size){
	int mini = 1000000000;
	for(int i=0;i<size;i++){
		if(arr[i]<mini)
			mini = arr[i];
	}
	return mini;
}
int maxi(int arr[],int size){
	int mini = 0;
	for(int i=0;i<size;i++){
		if(arr[i]>mini)
			mini = arr[i];
	}
	return mini;
}

int main(){
	string s;
	cin>>s;

	int x = 0 , y = 0;

	for(int i=0;i<s.size();i++){
		if(s[i]=='U')
			y++;
		else if(s[i]=='D')
			y--;
		else if(s[i]=='L')
			x--;
		else
			x++;
	}
	int counter = 0 ;
	int originalx = x;
	int originaly = y;
	if(((x==1)&&(y==1))||((x==1)&&(y==-1))||((x==-1)&&(y==1))||((x==-1)&&(y==-1)))
		cout<<++counter<<endl;
	else if(counter==s.size()||(x!=0||y!=0))
		cout<<"-1"<<endl;
	else{
		while(x!=0){
		if(originalx<0)
		{
			if(x>0)
				break;
		}
		if(originalx>0)
		{
			if(x<0)
				break;
		}
		if(x<0)
			x+=2;
		else if(x>0)
			x-=2;

		counter++;

	}
	while(y!=0){
		if(originaly<0)
		{
			if(y>0)
				break;
		}
		if(originaly>0)
		{
			if(y<0)
				break;
		}
		if(y<0)
			y+=2;
		else if(y>0)
			y-=2;

		counter++;
	}
	cout<<counter<<endl;
	}

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s;
   cin>>s;
   int i,a=0,b=0,c=0,d=0,ans,q,r;
   if(s.length()%2==1)
   {
       cout<<"-1";
       return 0;
   }
   for(i=0;i<s.length();i++)
   {
       if(s[i]=='L')
       a++;
       else if(s[i]=='R')
       b++;
       else if(s[i]=='U')
       c++;
       else
       d++;
   }
   if(c==0 && d==0)
   {
       cout<<abs(a-b);
       return 0;
   }
   if(a==0 && b==0)
   {
       cout<<abs(c-d);
       return 0;
   }
   cout<<abs(a-b)<<endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s;
   cin>>s;
   int i,a=0,b=0,c=0,d=0,ans=0,q,r,k;
   if(s.length()%2==1)
   {
       cout<<"-1";
       return 0;
   }
   for(i=0;i<s.length();i++)
   {
       if(s[i]=='L')
       a++;
       else if(s[i]=='R')
       b++;
       else if(s[i]=='U')
       c++;
       else
       d++;
   }
   if(c==0 && d==0)
   {
       q=max(a,b)-min(a,b);
       cout<<q/2;
       return 0;
   }
   if(a==0 && b==0)
   {
       q=max(c,d)-min(c,d);
       cout<<q/2;
       return 0;
   }
   k=max(a,b);
   r=min(c,d);
   while(1)
   {
        if(r==max(c,d))
       break;
       ans++;
       k--;
       r++;
   }
   if(k!=min(a,b)){
       q=k-min(a,b);
   ans=ans+q/2;
   }
   cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s;
   cin>>s;
   int i,a=0,b=0,c=0,d=0,ans=0,q,r,k;
   if(s.length()%2==1)
   {
       cout<<"-1";
       return 0;
   }
   for(i=0;i<s.length();i++)
   {
       if(s[i]=='L')
       a++;
       else if(s[i]=='R')
       b++;
       else if(s[i]=='U')
       c++;
       else
       d++;
   }
   if(c==0 && d==0)
   {
       cout<<abs(a-b);
       return 0;
   }
   if(a==0 && b==0)
   {
       cout<<abs(c-d);
       return 0;
   }
   k=max(a,b);
   r=min(c,d);
   while(1)
   {
       ans++;
       k--;
       r++;
       if(r==max(c,d))
       break;
   }
   if(k!=min(a,b))
   ans=ans+k/2;
   cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s;
   cin>>s;
   int i,a=0,b=0,c=0,d=0,ans,q,r;
   if(s.length()%2==1)
   {
       cout<<"-1";
       return 0;
   }
   for(i=0;i<s.length();i++)
   {
       if(s[i]=='L')
       a++;
       else if(s[i]=='R')
       b++;
       else if(s[i]=='U')
       c++;
       else
       d++;
   }
   if(c==0 && d==0)
   {
       cout<<max(a,b)/2;
       return 0;
   }
   if(a==0 && b==0)
   {
       cout<<max(c,d)/2;
       return 0;
   }
   cout<<abs(a-b)<<endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s;
   cin>>s;
   int i,a=0,b=0,c=0,d=0,ans=0,q,r,k;
   if(s.length()%2==1)
   {
       cout<<"-1";
       return 0;
   }
   for(i=0;i<s.length();i++)
   {
       if(s[i]=='L')
       a++;
       else if(s[i]=='R')
       b++;
       else if(s[i]=='U')
       c++;
       else
       d++;
   }
   if(c==0 && d==0)
   {
       cout<<max(a,b)/2;
       return 0;
   }
   if(a==0 && b==0)
   {
       cout<<max(c,d)/2;
       return 0;
   }
   k=max(a,b);
   r=min(c,d);
   while(1)
   {
       ans++;
       k--;
       r++;
       if(r==max(c,d))
       break;
   }
   if(k!=min(a,b))
   ans=ans+k/2;
   cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
char temp[100001];
int result;

int remove (char c1, char c2)
{
	if(c1 == 'L' && c2 == 'R')
		return 1;

	if(c1 == 'R' && c2 == 'L')
		return 1;

	if(c1 == 'U' && c2 == 'D')
		return 1;

	if(c1 == 'D' && c2 == 'U')
		return 1;

	return 0;
}

void check (char c, int vitri)
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(remove(temp[i],c) == 1)
		{
			temp[i] = 'A';
			temp[vitri] = 'A';

			return ;
		}
	}
}

void getResult()
{
	int i,size;
	int dem;

	dem = 0;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
		{
			dem++;
		}
	}

	if(dem == 0)
		result = 0;
	else
		result = dem / 2;
}

void solve ()
{
	int i;
	int size;

	size = strlen(s);
	strcpy(temp,s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
			check(temp[i],i);
	}

	getResult();
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
//	freopen(fi, "r" , stdin);
//	freopen(fo, "w" , stdout);

	gets(s);

	result = -1;

	if(strlen(s) % 2 == 0)
		solve();

	output();

	return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
int dem[10000];

int result;

void solve ()
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
		dem[s[i]]++;

	result = (strlen(s) - (min(dem['L'],dem['R']) * 2 + min(dem['U'],dem['D']) * 2)) / 2;
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
//	freopen(fi, "r" , stdin);
//	freopen(fo, "w" , stdout);

	gets(s);

	result = -1;

	if(strlen(s) % 2 == 0)
		solve();

	output();

	return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
char dem[255];

int result;

void solve ()
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		dem[s[i]]++;
	}

	result = (strlen(s) - (min(dem['L'],dem['R']) + min(dem['U'],dem['D']))) / 2;
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
	//freopen(fi, "r" , stdin);
//	freopen(fo, "w" , stdout);

	gets(s);

	result = -1;

	if(strlen(s) % 2 == 0)
		solve();

	output();

	return 0;
}


RUUR#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
char temp[100001];
int result;

int remove (char c1, char c2)
{
	if(c1 == 'L' && c2 == 'R')
		return 1;

	if(c1 == 'R' && c2 == 'L')
		return 1;

	if(c1 == 'U' && c2 == 'D')
		return 1;

	if(c1 == 'D' && c2 == 'U')
		return 2;
}

void check (char c, int vitri)
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(remove(temp[i],c) == 1)
		{
			temp[i] = 'A';
			temp[vitri] = 'A';

			return ;
		}
	}
}

void getResult()
{
	int i,size;
	int dem;

	dem = 0;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
		{
			dem++;
		}
	}

	result = dem / 2;
}

void solve ()
{
	int i;
	int size;

	size = strlen(s);
	strcpy(temp,s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
			check(temp[i],i);
	}

	getResult();
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
//	freopen(fi, "r" , stdin);
//	freopen(fo, "w" , stdout);

	while (1)
	{
		s[0] = -1;

		gets(s);

		if(s[0] == -1)
			break;

		result = -1;

		if(strlen(s) % 2 == 0)
			solve();

		output();
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
char temp[100001];
int result;

int remove (char c1, char c2)
{
	if(c1 == 'L' && c2 == 'R')
		return 1;

	if(c1 == 'R' && c2 == 'L')
		return 1;

	if(c1 == 'U' && c2 == 'D')
		return 1;

	if(c1 == 'D' && c2 == 'U')
		return 2;
}

void check (char c, int vitri)
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(remove(temp[i],c) == 1)
		{
			temp[i] = 'A';
			temp[vitri] = 'A';

			return ;
		}
	}
}

void getResult()
{
	int i,size;
	int dem;

	dem = 0;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
		{
			dem++;
		}
	}

	if(dem == 0)
		result = 0;
	else
		result = dem / 2;
}

void solve ()
{
	int i;
	int size;

	size = strlen(s);
	strcpy(temp,s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
			check(temp[i],i);
	}

	getResult();
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
//	freopen(fi, "r" , stdin);
//	freopen(fo, "w" , stdout);

	gets(s);

	result = -1;

	if(strlen(s) % 2 == 0)
		solve();

	output();

	return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
char temp[100001];
int result;

int remove (char c1, char c2)
{
	if(c1 == 'L' && c2 == 'R')
		return 1;

	if(c1 == 'R' && c2 == 'L')
		return 1;

	if(c1 == 'U' && c2 == 'D')
		return 1;

	if(c1 == 'D' && c2 == 'U')
		return 2;
}

void check (char c, int vitri)
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(remove(temp[i],c) == 1)
		{
			temp[i] = 'A';
			temp[vitri] = 'A';

			return ;
		}
	}
}

void getResult()
{
	int i,size;
	int dem;

	dem = 0;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
		{
			dem++;
		}
	}

	result = dem / 2;
}

void solve ()
{
	int i;
	int size;

	size = strlen(s);
	strcpy(temp,s);

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
			check(temp[i],i);
	}

	getResult();
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
//	freopen(fi, "r" , stdin);
//	freopen(fo, "w" , stdout);

	gets(s);

	result = -1;

	if(strlen(s) % 2 == 0)
		solve();

	output();

	return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>

using namespace std;

#define fi "b.inp"
#define fo "b.out"

char s[100001];
char temp[100001];
int result;
int dem;

int remove (char c1, char c2)
{
	if(c1 == 'L' && c2 == 'R')
		return 1;

	if(c1 == 'R' && c2 == 'L')
		return 1;

	if(c1 == 'U' && c2 == 'D')
		return 1;

	if(c1 == 'D' && c2 == 'U')
		return 1;

	return 0;
}

void check (char c, int vitri)
{
	int i,size;

	size = strlen(s);

	for(i = 0; i < size; i++)
	{
		if(remove(temp[i],c) == 1)
		{
			temp[i] = 'A';
			temp[vitri] = 'A';

			dem = dem + 2;

			return ;
		}
	}
}

void solve ()
{
	int i;
	int size;

	size = strlen(s);
	strcpy(temp,s);
	dem = 0;

	for(i = 0; i < size; i++)
	{
		if(temp[i] != 'A')
		{
			check(temp[i],i);
		}
	}

	result = (strlen(s) - dem) / 2;
}

void output ()
{
	printf("%d\n", result);
}

int main ()
{
	//freopen(fi, "r" , stdin);
	//freopen(fo, "w" , stdout);

	gets(s);

	result = -1;

	if(strlen(s) % 2 == 0)
		solve();

	output();

	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int x=0,y=0;
    string s;
    cin>>s;

    int i=0;
    while(s[i])
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='U')
            y++;
        else
            y--;
        i++;
    }

    if(x==y)
        cout<<x;
    else
        cout<<"-1";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int x=0,y=0;
    string s;
    cin>>s;

    int i=0;
    while(s[i])
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='U')
            y++;
        else
            y--;
        i++;
    }

    if(x%2==0&&y%2==0||(x==y))
        cout<<(x/2+y/2);
    else
        cout<<"-1";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int x=0,y=0;
    string s;
    cin>>s;

    int i=0;
    while(s[i])
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='U')
            y++;
        else
            y--;
        i++;
    }

    if(x%2==0&&y%2==0)
        cout<<(x/2+y/2);
    else if(x==y)
        cout<<x;
    else
        cout<<"-1";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    long x=0,y=0;
    string s;
    cin>>s;

    long i=0;
    while(s[i])
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='U')
            y++;
        else
            y--;
        i++;
    }

    //cout<<(-2%2);
    if(abs(x)%2==0&&abs(y)%2==0)
        cout<<(abs(x/2)+abs(y/2));
    else if(x==y)
        cout<<abs(x);
    else if((abs(x)+abs(y))%2==0)
        cout<<((abs(x)+abs(y))/2);
    else
        cout<<"-1";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    long x=0,y=0;
    string s;
    cin>>s;

    long i=0;
    while(s[i])
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='U')
            y++;
        else
            y--;
        i++;
    }

    if(x%2==0&&y%2==0)
        cout<<(abs(x/2)+abs(y/2));
    else if(x==y)
        cout<<abs(x);
    else
        cout<<"-1";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    long x=0,y=0;
    string s;
    cin>>s;

    long i=0;
    while(s[i])
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='U')
            y++;
        else
            y--;
        i++;
    }

    if(x%2==0&&y%2==0)
        cout<<(x/2+y/2);
    else if(x==y)
        cout<<x;
    else
        cout<<"-1";
    return 0;
}


#include <bits/stdc++.h>
#include <ctime>
using namespace std;

namespace MyNamespace {
#define space ' '
#define enter "\n"
#define fi first
#define se second
#define INF 2000000007
#define mp make_pair

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef set<int> si;
    typedef map<int, int> mii;
    typedef pair<ll, ll> pll;
    typedef vector<int> vi;
    typedef vector<pii> vii;

    template<typename T>
    T sqr (T x) {
        return x * x;
    }

    template<typename T>
    T gcd (T a, T b) {
        return b ? gcd(b, a % b) : a;
    }

    template<class T>
    T chmin (T &x, const T &y) {
        if (y < x)
            return x = y;
        return x;
    }

    template<class T>
    T chmax (T &x, const T &y) {
        if (x < y)
            return x = y;
        return x;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const pair<P, Q> &p) {
        return os << '(' << p.fi << ", " << p.se << ')';
    }

    template<class T>
    ostream &operator<< (ostream &os, const vector<T> &v) {
        os << '{';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '}';
        return os;
    }

    template<class T>
    ostream &operator<< (ostream &os, const set<T> &v) {
        os << '[';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << ']';
        return os;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const map<P, Q> &m) {
        os << '<';
        bool was = false;
        for (const auto &x : m) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '>';
        return os;
    }
}

using namespace MyNamespace;

string s;
int x, y;
int U, D, R, L;
int ans;
int II;

int main () {
    ios_base::sync_with_stdio(false);
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U')
			x++, U++;
		if (s[i] == 'D')
			x--, D++;
		if (s[i] == 'R')
			y++, R++;
		if (s[i] == 'L')
			y--, L++;
	}
	while (x || y) {
		II++;
		if (II > s.size()) {
			cout << -1;
			return 0;
		}
		if (x > 0 && y > 0) {
			if (R)
				R--, ans++, x--, y--;
		}
		if (x < 0 && y < 0) {
			if (L)
				L--, ans++, x++, y++;
		}
		if (x < 0 && y > 0) {
			if (U)
				U--, ans++, x++, y--;
		}
		if (x > 0 && y < 0) {
			if (D)
				D--, ans++, x--, y++;
		}
		if (x > 0 && y == 0) {
			if (D)
				D--, ans++, x -= 2;
		}
		if (x < 0 && y == 0) {
			if (U)
				U--, ans++, x += 2;
		}
		if (x == 0 && y > 0) {
			if (L)
				L--, ans++, y -= 2;
		}
		if (x == 0 && y < 0) {
			if (R)
				R--, ans++, y -= 2;
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>
#include <ctime>
using namespace std;

namespace MyNamespace {
#define space ' '
#define enter "\n"
#define fi first
#define se second
#define INF 2000000007
#define mp make_pair

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef set<int> si;
    typedef map<int, int> mii;
    typedef pair<ll, ll> pll;
    typedef vector<int> vi;
    typedef vector<pii> vii;

    template<typename T>
    T sqr (T x) {
        return x * x;
    }

    template<typename T>
    T gcd (T a, T b) {
        return b ? gcd(b, a % b) : a;
    }

    template<class T>
    T chmin (T &x, const T &y) {
        if (y < x)
            return x = y;
        return x;
    }

    template<class T>
    T chmax (T &x, const T &y) {
        if (x < y)
            return x = y;
        return x;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const pair<P, Q> &p) {
        return os << '(' << p.fi << ", " << p.se << ')';
    }

    template<class T>
    ostream &operator<< (ostream &os, const vector<T> &v) {
        os << '{';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '}';
        return os;
    }

    template<class T>
    ostream &operator<< (ostream &os, const set<T> &v) {
        os << '[';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << ']';
        return os;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const map<P, Q> &m) {
        os << '<';
        bool was = false;
        for (const auto &x : m) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '>';
        return os;
    }
}

using namespace MyNamespace;

string s;
int x, y;
int U, D, R, L;
int ans;
int II;

int main () {
    ios_base::sync_with_stdio(false);
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U')
			x++, U++;
		if (s[i] == 'D')
			x--, D++;
		if (s[i] == 'R')
			y++, R++;
		if (s[i] == 'L')
			y--, L++;
	}
	ans = abs(x - y) / 2;
	int mi = min(x, y);
	x = y = mi;
	cout << ans + mi;
}


#include <bits/stdc++.h>
#include <ctime>
using namespace std;

namespace MyNamespace {
#define space ' '
#define enter "\n"
#define fi first
#define se second
#define INF 2000000007
#define mp make_pair

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef set<int> si;
    typedef map<int, int> mii;
    typedef pair<ll, ll> pll;
    typedef vector<int> vi;
    typedef vector<pii> vii;

    template<typename T>
    T sqr (T x) {
        return x * x;
    }

    template<typename T>
    T gcd (T a, T b) {
        return b ? gcd(b, a % b) : a;
    }

    template<class T>
    T chmin (T &x, const T &y) {
        if (y < x)
            return x = y;
        return x;
    }

    template<class T>
    T chmax (T &x, const T &y) {
        if (x < y)
            return x = y;
        return x;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const pair<P, Q> &p) {
        return os << '(' << p.fi << ", " << p.se << ')';
    }

    template<class T>
    ostream &operator<< (ostream &os, const vector<T> &v) {
        os << '{';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '}';
        return os;
    }

    template<class T>
    ostream &operator<< (ostream &os, const set<T> &v) {
        os << '[';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << ']';
        return os;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const map<P, Q> &m) {
        os << '<';
        bool was = false;
        for (const auto &x : m) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '>';
        return os;
    }
}

using namespace MyNamespace;

string s;
int x, y;
int U, D, R, L;
int ans;
int II;

int main () {
    ios_base::sync_with_stdio(false);
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U')
			x++, U++;
		if (s[i] == 'D')
			x--, D++;
		if (s[i] == 'R')
			y++, R++;
		if (s[i] == 'L')
			y--, L++;
	}
	while (x || y) {
		if (x > 0 && y == 0) {
			if (D)
				D--, ans++, x -= 2;
			continue;
		}
		if (x < 0 && y == 0) {
			if (U)
				U--, ans++, x += 2;
			continue;
		}
		if (x == 0 && y > 0) {
			if (L)
				L--, ans++, y -= 2;
			continue;
		}
		if (x == 0 && y < 0) {
			if (R)
				R--, ans++, y -= 2;
			continue;
		}

		if (x > 0 && y > 0) {
			if (R)
				R--, ans++, x--, y--;
			continue;
		}
		if (x < 0 && y < 0) {
			if (L)
				L--, ans++, x++, y++;
			continue;
		}
		if (x < 0 && y > 0) {
			if (U)
				U--, ans++, x++, y--;
			continue;
		}
		if (x > 0 && y < 0) {
			if (D)
				D--, ans++, x--, y++;
			continue;
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>
#include <ctime>
using namespace std;

namespace MyNamespace {
#define space ' '
#define enter "\n"
#define fi first
#define se second
#define INF 2000000007
#define mp make_pair

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef set<int> si;
    typedef map<int, int> mii;
    typedef pair<ll, ll> pll;
    typedef vector<int> vi;
    typedef vector<pii> vii;

    template<typename T>
    T sqr (T x) {
        return x * x;
    }

    template<typename T>
    T gcd (T a, T b) {
        return b ? gcd(b, a % b) : a;
    }

    template<class T>
    T chmin (T &x, const T &y) {
        if (y < x)
            return x = y;
        return x;
    }

    template<class T>
    T chmax (T &x, const T &y) {
        if (x < y)
            return x = y;
        return x;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const pair<P, Q> &p) {
        return os << '(' << p.fi << ", " << p.se << ')';
    }

    template<class T>
    ostream &operator<< (ostream &os, const vector<T> &v) {
        os << '{';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '}';
        return os;
    }

    template<class T>
    ostream &operator<< (ostream &os, const set<T> &v) {
        os << '[';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << ']';
        return os;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const map<P, Q> &m) {
        os << '<';
        bool was = false;
        for (const auto &x : m) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '>';
        return os;
    }
}

using namespace MyNamespace;

string s;
int x, y;
int U, D, R, L;
int ans;
int II;

int main () {
    ios_base::sync_with_stdio(false);
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U')
			x++, U++;
		if (s[i] == 'D')
			x--, D++;
		if (s[i] == 'R')
			y++, R++;
		if (s[i] == 'L')
			y--, L++;
	}
	while (x || y) {
		II++;
		if (II > s.size()) {
			cout << -1;
			return 0;
		}

		if (x > 0 && y == 0) {
			if (D)
				D--, ans++, x -= 2;
			continue;
		}
		if (x < 0 && y == 0) {
			if (U)
				U--, ans++, x += 2;
			continue;
		}
		if (x == 0 && y > 0) {
			if (L)
				L--, ans++, y -= 2;
			continue;
		}
		if (x == 0 && y < 0) {
			if (R)
				R--, ans++, y -= 2;
			continue;
		}

		if (x > 0 && y > 0) {
			if (R)
				R--, ans++, x--, y--;
			continue;
		}
		if (x < 0 && y < 0) {
			if (L)
				L--, ans++, x++, y++;
			continue;
		}
		if (x < 0 && y > 0) {
			if (U)
				U--, ans++, x++, y--;
			continue;
		}
		if (x > 0 && y < 0) {
			if (D)
				D--, ans++, x--, y++;
			continue;
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>
#include <ctime>
using namespace std;

namespace MyNamespace {
#define space ' '
#define enter "\n"
#define fi first
#define se second
#define INF 2000000007
#define mp make_pair

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef set<int> si;
    typedef map<int, int> mii;
    typedef pair<ll, ll> pll;
    typedef vector<int> vi;
    typedef vector<pii> vii;

    template<typename T>
    T sqr (T x) {
        return x * x;
    }

    template<typename T>
    T gcd (T a, T b) {
        return b ? gcd(b, a % b) : a;
    }

    template<class T>
    T chmin (T &x, const T &y) {
        if (y < x)
            return x = y;
        return x;
    }

    template<class T>
    T chmax (T &x, const T &y) {
        if (x < y)
            return x = y;
        return x;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const pair<P, Q> &p) {
        return os << '(' << p.fi << ", " << p.se << ')';
    }

    template<class T>
    ostream &operator<< (ostream &os, const vector<T> &v) {
        os << '{';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '}';
        return os;
    }

    template<class T>
    ostream &operator<< (ostream &os, const set<T> &v) {
        os << '[';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << ']';
        return os;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const map<P, Q> &m) {
        os << '<';
        bool was = false;
        for (const auto &x : m) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '>';
        return os;
    }
}

using namespace MyNamespace;

string s;
int x, y;
int U, D, R, L;
int ans;
int II;

int main () {
    ios_base::sync_with_stdio(false);
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U')
			x++, U++;
		if (s[i] == 'D')
			x--, D++;
		if (s[i] == 'R')
			y++, R++;
		if (s[i] == 'L')
			y--, L++;
	}
	x = abs(x), y = abs(y);
	ans = abs(x - y) / 2;
	int mi = min(x, y);
	x = y = mi;
	cout << ans + mi;
}


#include <bits/stdc++.h>
#include <ctime>
using namespace std;

namespace MyNamespace {
#define space ' '
#define enter "\n"
#define fi first
#define se second
#define INF 2000000007
#define mp make_pair

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> pii;
    typedef set<int> si;
    typedef map<int, int> mii;
    typedef pair<ll, ll> pll;
    typedef vector<int> vi;
    typedef vector<pii> vii;

    template<typename T>
    T sqr (T x) {
        return x * x;
    }

    template<typename T>
    T gcd (T a, T b) {
        return b ? gcd(b, a % b) : a;
    }

    template<class T>
    T chmin (T &x, const T &y) {
        if (y < x)
            return x = y;
        return x;
    }

    template<class T>
    T chmax (T &x, const T &y) {
        if (x < y)
            return x = y;
        return x;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const pair<P, Q> &p) {
        return os << '(' << p.fi << ", " << p.se << ')';
    }

    template<class T>
    ostream &operator<< (ostream &os, const vector<T> &v) {
        os << '{';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '}';
        return os;
    }

    template<class T>
    ostream &operator<< (ostream &os, const set<T> &v) {
        os << '[';
        bool was = false;
        for (const T &x : v) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << ']';
        return os;
    }

    template<class P, class Q>
    ostream &operator<< (ostream &os, const map<P, Q> &m) {
        os << '<';
        bool was = false;
        for (const auto &x : m) {
            if (was)
                os << ", ";
            was = true;
            os << x;
        }
        os << '>';
        return os;
    }
}

using namespace MyNamespace;

string s;
int x, y;
int U, D, R, L;
int ans;

int main () {
    ios_base::sync_with_stdio(false);
	cin >> s;
	if (s.size() % 2 == 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'U')
			x++, U++;
		if (s[i] == 'D')
			x--, D++;
		if (s[i] == 'R')
			y++, R++;
		if (s[i] == 'L')
			y--, L++;
	}
	while (x || y) {
		if (x > 0 && y > 0) {
			if (R)
				R--, ans++, x--, y--;
		}
		if (x < 0 && y < 0) {
			if (L)
				L--, ans++, x++, y++;
		}
		if (x < 0 && y > 0) {
			if (U)
				U--, ans++, x++, y--;
		}
		if (x > 0 && y < 0) {
			if (D)
				D--, ans++, x--, y++;
		}
		if (x > 0 && y == 0) {
			if (D)
				D--, ans++, x -= 2;
		}
		if (x < 0 && y == 0) {
			if (U)
				U--, ans++, x += 2;
		}
		if (x == 0 && y > 0) {
			if (L)
				L--, ans++, y -= 2;
		}
		if (x == 0 && y < 0) {
			if (R)
				R--, ans++, y -= 2;
		}
	}
	cout << ans;
}


#include<iostream>
#include<string.h>
using namespace std;
typedef long long lll;

lll gg(lll o)
{
	if(o<0)
		o=o*-1;
	return o;
}
char str[100001];
int main()
{
	cin>>str;
	lll l=strlen(str);
	lll l1=0,l2=0,l3=0,l4=0;
	for(lll i=0;i<l;i++)
	{
		if(str[i]=='R')
			l1++;
		else if(str[i]=='U')
			l2++;
		else if(str[i]=='L')
			l3++;
		else if(str[i]=='D')
			l4++;
	}
	lll arr[4];
	arr[0]=l1;
	arr[1]=l2;
	arr[2]=l3;
	arr[3]=l4;
        if(l==2)
                {
                        if(arr[0]=='R'&&arr[0]=='L')
					cout<<"-1\n";
			else if(arr[0]=='L'&&arr[0]=='R')
					cout<<"-1\n";
                        else if(arr[0]=='U'&&arr[0]=='D')
                                        cout<<"-1\n";
                        else if(arr[0]=='D'&&arr[0]=='U')
                                        cout<<"-1\n";
			else
				cout<<"1\n";
			return 0;
                }

	if((l)%4==0)
		{
			lll sum=l1+l2+l3+l4;
			lll f=sum/4;
			lll d1,d2,d3,d4;
			d1=gg(arr[0]-f);
			d2=gg(arr[1]-f);
			d3=gg(arr[2]-f);
			d4=gg(arr[3]-f);
			lll s=d1+d2+d3+d4;
			if(s==0)
				cout<<"-1"<<endl;
			else
				cout<<s/2<<endl;
		}
	else
		cout<<"-1\n";
return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
typedef long long lll;

lll gg(lll o)
{
	if(o<0)
		o=o*-1;
	return o;
}
char str[100001];
int main()
{
	cin>>str;
	lll l=strlen(str);
	lll l1=0,l2=0;
	for(lll i=0;i<l;i++)
	{
		if(str[i]=='R')
		{
			l1++;
		}
		else if(str[i]=='U')
		{	l2++;
		}
		else if(str[i]=='L')
		{	l1--;
		}
		else if(str[i]=='D')
		{	l2--;
		}
	}
	if(l%2==1)
		{
			cout<<"-1\n";
		}
	else
		cout<<(l1+l2)/2<<endl;

return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
typedef long long lll;

lll gg(lll o)
{
	if(o<0)
		o=o*-1;
	return o;
}
char str[100001];
int main()
{
	cin>>str;
	lll l=strlen(str);
	lll l1=0,l2=0;
	for(lll i=0;i<l;i++)
	{
		if(str[i]=='R')
		{
			l1++;
		}
		else if(str[i]=='U')
		{	l2++;
		}
		else if(str[i]=='L')
		{	l1--;
		}
		else if(str[i]=='D')
		{	l2--;
		}
	}
	if(l%2==1)
		{
			cout<<"-1\n";
		}
	else
		cout<<(gg(l1)+gg(l2))/2<<endl;

return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
typedef long long lll;

lll gg(lll o)
{
	if(o<0)
		o=o*-1;
	return o;
}
char str[100001];
int main()
{
	cin>>str;
	lll l=strlen(str);
	lll l1=0,l2=0,l3=0,l4=0;
	for(lll i=0;i<l;i++)
	{
		if(str[i]=='R')
			l1++;
		else if(str[i]=='U')
			l2++;
		else if(str[i]=='L')
			l3++;
		else if(str[i]=='D')
			l4++;
	}
	lll arr[4];
	arr[0]=l1;
	arr[1]=l2;
	arr[2]=l3;
	arr[3]=l4;
        if(l==2)
                {
                        if(arr[0]=='R'&&arr[0]=='L')
					cout<<"0\n";
			else if(arr[0]=='L'&&arr[0]=='R')
					cout<<"0\n";
                        else if(arr[0]=='U'&&arr[0]=='D')
                                        cout<<"0\n";
                        else if(arr[0]=='D'&&arr[0]=='U')
                                        cout<<"0\n";
			else
				cout<<"1\n";
			return 0;
                }

	if((l)%4==0)
		{
			lll sum=l1+l2+l3+l4;
			lll f=sum/4;
			lll d1,d2,d3,d4;
			d1=gg(arr[0]-f);
			d2=gg(arr[1]-f);
			d3=gg(arr[2]-f);
			d4=gg(arr[3]-f);
			cout<<(d1+d2+d3+d4)/2<<endl;
		}
	else
		cout<<"-1\n";
return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
typedef long long lll;

lll gg(lll o)
{
	if(o<0)
		o=o*-1;
	return o;
}
char str[100001];
int main()
{
//	char sttr[100001];
	cin>>str;

	lll l=strlen(str);
	lll l1=0,l2=0,l3=0,l4=0;
	for(lll i=0;i<l;i++)
	{
		if(str[i]=='R')
			l1++;
		else if(str[i]=='U')
			l2++;
		else if(str[i]=='L')
			l3++;
		else if(str[i]=='D')
			l4++;
	}
	lll arr[4];
	arr[0]=l1;
	arr[1]=l2;
	arr[2]=l3;
	arr[3]=l4;
	if((l)%4==0)
		{
			lll sum=l1+l2+l3+l4;
			lll f=sum/4;
			lll d1,d2,d3,d4;
			d1=gg(arr[0]-f);
			d2=gg(arr[1]-f);
			d3=gg(arr[2]-f);
			d4=gg(arr[3]-f);
			cout<<(d1+d2+d3+d4)/2<<endl;
		}
	else
		cout<<"-1\n";
return 0;
}


#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cstdio>
#include <vector>
#include <utility>
#include <cstring>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define PI acos(-1)
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define N 200005
#define LIM 10000000
#define newmax(a,b) a>b?a:b
#define newmin(a,b) a>b?b:a
#define Lowbit(x) (x&-x)
using namespace std;
typedef long long int LL;
const int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };

int main()
{
    char s[N]={0};
    gets(s);
    int len=strlen(s);
    if(len%2!=0)
    {
        printf("-1\n");
    }
    else
    {
        int ha[300]={0};
        for(int i=0;s[i];i++)
        {
            ha[s[i]]++;
        }
        int a1=max(ha['U'],ha['D'])-min(ha['U'],ha['D']);
        int a2=max(ha['R'],ha['L'])-min(ha['R'],ha['L']);
        printf("%d\n",(a1+a2)/2 );
    }
    return 0;
}


#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define mem(a,b) memset(a,0,sizeof(a))
#define fori(a,b) for(int i=a;i<=b;i++)
#define forj(a,b) for(int j=a;j<=b;j++)
#define fork(a,b) for(int k=a;k<=b;k++)
#define ifor(a,b) for(int i=a;i>=b;i--)
#define jfor(a,b) for(int j=a;j>=b;j--)

using namespace std;
typedef long long LL;

int main()
{
    int r=0,d=0,l=0,u=0,ans=0;
    char a[100001];
    mem(a,0);
    scanf(" %s",a);
    int len=strlen(a);
    if(len%2!=0)
    {
        printf("-1\n");
        return 0;
    }
    fori(0,len-1)
    {
        if(a[i]=='R')
            r++;
        else if(a[i]=='L')
            l++;
        else if(a[i]=='U')
            u++;
        else if(a[i]=='D')
            d++;
    }
    int x=fabs(r-l);
    int y=fabs(u-d);
    if(x>y)
    {
        x-=y;
        if(x%2==0)
            ans=y+x/2;
        else
            ans=y+x/2+1;
    }
    else if(x<y)
    {
        y-=x;
        if(y%2==0)
            ans=x+y/2;
        else
            ans=x+y/2+1;
    }
    else if(x==y)
        ans=x;
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<ll,ll> M;
char s[100100];
int main()
{
    memset(s,0,sizeof(s));
    ll n,ans=0,i,j,l=0,r=0,u=0,d=0;
    cin>>s;
    n=strlen(s);
    if(n%2!=0)
        cout<<"-1"<<endl;
    else
    {
        for(i=0;i<n;i++)
        {
            if(s[i]=='L')
                l++;
            else
            if(s[i]=='R')
                r++;
            else
            if(s[i]=='U')
                u++;
            else
            if(s[i]=='D')
                d++;
        }
        ll ans1=0,ans2=0;
        ans1=max(l,r)-min(l,r);
        ans2=max(u,d)-min(u,d);
        if(ans1==ans2)
            cout<<ans1<<endl;
        else
            cout<<n/2<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;

char a[111111];
int b[4];
int main()
{
    cin>>a;
    int l=strlen(a);
    if(l%2)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    for(int i=0;i<l;i++)
    {
        if(a[i]=='L')
            b[0]++;
        if(a[i]=='R')
            b[0]--;
        if(a[i]=='U')
            b[1]++;
        if(a[i]=='D')
            b[1]--;
    }
    //cout<<b[0]<<" "<<b[1]<<endl;
    cout<<(abs(b[0])+abs(b[1]))/2<<endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long  LL;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 100009;

char con[N];
int main()
{
    int i,p,j,n;
    int a,b,c,d;
    a=b=c=d=0;
    scanf("%s",con);
    int k=strlen(con);
    for(i=0;i<k;i++)
    {
        if(con[i]=='L')
            a++;
        else if(con[i]=='R')
            b++;
        else if(con[i]=='U')
            c++;
        else
            d++;
    }
    int x,y;
    x=abs(a-b);
    y=abs(c-d);
//    if(x%2==0&&y%2==0)
    if((x+y)%2==0)
    {
        printf("%d\n",(x+y)/2);
    }
    else
        printf("-1\n");
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

int main()
{
  string x;
  bool m=false ;
  cin>>x;
  int cu=0,cr=0;
  for (long long i=0;i<x.length();i++){
        if (x[i]=='U') cu++;
  else  if (x[i]=='D') cu--;
  else  if (x[i]=='R') cr++;
  else  if (x[i]=='L') cr--;
  }
  if (abs(cu)==abs(cr)) {
    cout<<cu<<endl;
  }
  if (cu>0 && cr>0 && cu>cr){
    cu=cu-cr;
    cr=0;
  }
else if (cu>0 && cr>0 && cr>cu){
    cr=cr-cu;
    cu=0;
  }
else if (cu<0 && cr<0 && cr<cu){
    cr=cr-cu;
    cu=0;
  }
  else if (cu<0 && cr<0 && cr>cu){
    cu=cu-cr;
    cr=0;
  }
  else if (cu>0 && cr<0 && cu>abs(cr) ){
    cu=cu+cr;
    cr=0;
  }
   else if (cu>0 && cr<0 && cu<abs(cr) ){
    cr=cu+cr;
    cu=0;
  }
    else if (cu<0 && cr>0 && cr>abs(cu) ){
    cr=cu+cr;
    cu=0;
  }
   else if (cu<0 && cr>0 && cr<abs(cu) ){
    cu=cu+cr;
    cr=0;
  }

  else if (abs(cu)>0 && abs(cu)%2==0 && cr==0){
    cout<<(abs(cu)/2)<<endl;
    m=true;
  }
    else if (abs(cr)>0 &&abs(cr)%2==0&&  cu==0 ){
     cout<<(abs(cr)/2)<<endl;
     m=true;
    }
  if (abs(cr)>0 && cu==0 &&  m==false) {cout <<"-1"<<endl;}
  else if (abs(cu)>0 && cr==0 && m==false){cout<<"-1"<<endl;}
  else if (cu==0 && cr==0){cout <<"0"<<endl;}

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

int main()
{
  string x;
  bool m=false ;
  cin>>x;
  int cu=0,cr=0;
  for (long long i=0;i<x.length();i++){
        if (x[i]=='U') cu++;
  else  if (x[i]=='D') cu--;
  else  if (x[i]=='R') cr++;
  else  if (x[i]=='L') cr--;
  }
  if (abs(cu)==abs(cr)) {
    cout<<cu<<endl;
  }
  if (cu>0 && cr>0 && cu>cr){
    cu=cu+cr;
    cr=0;
  }
else if (cu>0 && cr>0 && cr>cu){
    cr=cr+cu;
    cu=0;
  }
else if (cu<0 && cr<0 && cr<cu){
    cr=cr+cu;
    cu=0;
  }
  else if (cu<0 && cr<0 && cr>cu){
    cu=cu+cr;
    cr=0;
  }
  else if (cu>0 && cr<0 && cu>abs(cr) ){
    cu=cu-cr;
    cr=0;
  }
   else if (cu>0 && cr<0 && cu<abs(cr) ){
    cr=cu-cr;
    cu=0;
  }
    else if (cu<0 && cr>0 && cr>abs(cu) ){
    cr=cu-cr;
    cu=0;
  }
   else if (cu<0 && cr>0 && cr<abs(cu) ){
    cu=cu-cr;
    cr=0;
  }

   if (abs(cu)>0 && abs(cu)%2==0 && cr==0){
    cout<<(abs(cu)/2)<<endl;
    m=true;
  }
    else if (abs(cr)>0 &&abs(cr)%2==0&&  cu==0 ){
     cout<<(abs(cr)/2)<<endl;
     m=true;
    }
  if (abs(cr)>0 && cu==0 &&  m==false) {cout <<"-1"<<endl;}
  else if (abs(cu)>0 && cr==0 && m==false){cout<<"-1"<<endl;}
  else if (cu==0 && cr==0){cout <<"0"<<endl;}

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

int main()
{
  string x;
  cin>>x;
  int cu=0,cr=0;
  for (long long i=0;i<x.length();i++){
        if (x[i]=='U') cu++;
  else  if (x[i]=='D') cu--;
  else  if (x[i]=='R') cr++;
  else  if (x[i]=='L') cr--;
  }
  if (abs(cu)==abs(cr)) {
    cout<<cu<<endl;
  }
  if (cu>0 && cr>0 && cu>cr){
    cu=cu-cr;
    cr=0;
  }
else if (cu>0 && cr>0 && cr>cu){
    cr=cr-cu;
    cu=0;
  }
else if (cu<0 && cr<0 && cr<cu){
    cr=cr-cu;
    cu=0;
  }
  else if (cu<0 && cr<0 && cr>cu){
    cu=cu-cr;
    cr=0;
  }
  else if (cu>0 && cr<0 && cu>abs(cr) ){
    cu=cu+cr;
    cr=0;
  }
   else if (cu>0 && cr<0 && cu<abs(cr) ){
    cr=cu+cr;
    cu=0;
  }
    else if (cu<0 && cr>0 && cr>abs(cu) ){
    cr=cu+cr;
    cu=0;
  }
   else if (cu<0 && cr>0 && cr<abs(cu) ){
    cu=cu+cr;
    cr=0;
  }
  if (abs(cr)>0 && cu==0) {cout <<"-1"<<endl;}
  else if (abs(cu)>0 && cr==0){cout<<"-1"<<endl;}
  else if (cu==0 && cr==0){cout <<"0"<<endl;}

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

int main()
{
  string x;
  bool m=false ;
  cin>>x;
  int cu=0,cr=0;
  for (long long i=0;i<x.length();i++){
        if (x[i]=='U') cu++;
  else  if (x[i]=='D') cu--;
  else  if (x[i]=='R') cr++;
  else  if (x[i]=='L') cr--;
  }
  if (abs(cu)==abs(cr)&& cu!=0) {
    cout<<abs(cu)<<endl;
  }
  if (cu>0 && cr>0 && cu>cr){
    cu=cu+cr;
    cr=0;
  }
else if (cu>0 && cr>0 && cr>cu){
    cr=cr+cu;
    cu=0;
  }
else if (cu<0 && cr<0 && cr<cu){
    cr=cr+cu;
    cu=0;
  }
  else if (cu<0 && cr<0 && cr>cu){
    cu=cu+cr;
    cr=0;
  }
  else if (cu>0 && cr<0 && cu>abs(cr) ){
    cu=cu-cr;
    cr=0;
  }
   else if (cu>0 && cr<0 && cu<abs(cr) ){
    cr=cu-cr;
    cu=0;
  }
    else if (cu<0 && cr>0 && cr>abs(cu) ){
    cr=cu-cr;
    cu=0;
  }
   else if (cu<0 && cr>0 && cr<abs(cu) ){
    cu=cu-cr;
    cr=0;
  }

   if (abs(cu)>0 && abs(cu)%2==0 && cr==0){
    cout<<(abs(cu)/2)<<endl;
    m=true;
  }
    else if (abs(cr)>0 &&abs(cr)%2==0&&  cu==0 ){
     cout<<(abs(cr)/2)<<endl;
     m=true;
    }
  if (abs(cr)>0 && cu==0 &&  m==false) {cout <<"-1"<<endl;}
  else if (abs(cu)>0 && cr==0 && m==false){cout<<"-1"<<endl;}
  else if (cu==0 && cr==0){cout <<"0"<<endl;}

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

int main()
{
  string x;
  bool m=false ;
  cin>>x;
  int cu=0,cr=0;
  for (long long i=0;i<x.length();i++){
        if (x[i]=='U') cu++;
  else  if (x[i]=='D') cu--;
  else  if (x[i]=='R') cr++;
  else  if (x[i]=='L') cr--;
  }
  if (abs(cu)==abs(cr)) {
    cout<<abs(cu)<<endl;
  }
  if (cu>0 && cr>0 && cu>cr){
    cu=cu+cr;
    cr=0;
  }
else if (cu>0 && cr>0 && cr>cu){
    cr=cr+cu;
    cu=0;
  }
else if (cu<0 && cr<0 && cr<cu){
    cr=cr+cu;
    cu=0;
  }
  else if (cu<0 && cr<0 && cr>cu){
    cu=cu+cr;
    cr=0;
  }
  else if (cu>0 && cr<0 && cu>abs(cr) ){
    cu=cu-cr;
    cr=0;
  }
   else if (cu>0 && cr<0 && cu<abs(cr) ){
    cr=cu-cr;
    cu=0;
  }
    else if (cu<0 && cr>0 && cr>abs(cu) ){
    cr=cu-cr;
    cu=0;
  }
   else if (cu<0 && cr>0 && cr<abs(cu) ){
    cu=cu-cr;
    cr=0;
  }

   if (abs(cu)>0 && abs(cu)%2==0 && cr==0){
    cout<<(abs(cu)/2)<<endl;
    m=true;
  }
    else if (abs(cr)>0 &&abs(cr)%2==0&&  cu==0 ){
     cout<<(abs(cr)/2)<<endl;
     m=true;
    }
  if (abs(cr)>0 && cu==0 &&  m==false) {cout <<"-1"<<endl;}
  else if (abs(cu)>0 && cr==0 && m==false){cout<<"-1"<<endl;}
  else if (cu==0 && cr==0){cout <<"0"<<endl;}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main()
{
    string s;
    cin >> s;
    int result = 0;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size() - 1;i++)
    {
        if ((s[i] == 'U' && s[i + 1] != 'D') || (s[i] == 'D' && s[i + 1] != 'U'))
        {
            result++;
            i++;
        }
        if((s[i] == 'L' && s[i+1] != 'R') || (s[i] == 'R' && s[i+1] != 'L'))
        {
            result++;
            i++;
        }
    }
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main()
{
    string s;
    cin >> s;
    int result = 0;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size();i++)
    {
        if ((s[i] == 'U' && s[i + 1] != 'D') || (s[i] == 'D' && s[i + 1] != 'U'))result++;
        else if((s[i] == 'L' && s[i+1] != 'R') || (s[i] == 'R' && s[i+1] != 'L'))result++;
    }
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main()
{
    string s;
    cin >> s;
    int result = 0;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size();i++)
    {
        if ((s[i] == 'U' && s[i + 1] != 'D') || (s[i] == 'D' && s[i + 1] != 'U'))result++;
        else if((s[i] == 'L' && s[i+1] != 'R') || (s[i] == 'L' && s[i+1] != 'R'))result++;
    }
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int arr[4];
int main()
{
    string s;
    cin >> s;
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] == 'U')arr[0]++;
        if (s[i] == 'D')arr[1]++;
        if (s[i] == 'L')arr[2]++;
        if (s[i] == 'R')arr[3]++;
    }
    int result = abs ((arr[0] - arr[1])+abs(arr[2]-arr[3]));
    if(result % 2 == 1)
    {
    cout<< -1 <<endl;
    return 0;
    }
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main()
{
    string s;
    cin >> s;
    int result = 0;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size() - 1;i+=2)
    {
        if ((s[i] == 'U' && s[i + 1] != 'D') || (s[i] == 'D' && s[i + 1] != 'U'))
        {
            result++;
        }
        if((s[i] == 'L' && s[i+1] != 'R') || (s[i] == 'R' && s[i+1] != 'L'))
        {
            result++;
        }
    }
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int arr[4];
int main()
{
    string s;
    cin >> s;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] == 'U')arr[0]++;
        if (s[i] == 'D')arr[1]++;
        if (s[i] == 'L')arr[2]++;
        if (s[i] == 'R')arr[3]++;
    }
    int result = abs ((arr[0] - arr[1])+abs(arr[2]-arr[3])) / 2;
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int arr[4];
int main()
{
    string s;
    cin >> s;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] == 'U')arr[0]++;
        if (s[i] == 'D')arr[1]++;
        if (s[i] == 'L')arr[2]++;
        if (s[i] == 'R')arr[3]++;
    }

    if(arr[0]<arr[1])swap(arr[0] , arr[1]);
    if(arr[2]<arr[3])swap(arr[2] , arr[3]);
    arr[0]-=arr[1];arr[2]-=arr[3];
    int ans = arr[0]+arr[2];
    cout << ans/2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int arr[4];
int main()
{
    string s;
    cin >> s;
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] == 'U')arr[0]++;
        if (s[i] == 'D')arr[1]++;
        if (s[i] == 'L')arr[2]++;
        if (s[i] == 'R')arr[3]++;
    }
    int result = abs(arr[0] - arr[1])+abs(arr[2]-arr[3]);
    if(result % 2 == 1)
    {
    cout<< -1 <<endl;
    return 0;
    }
    cout << result/2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main()
{
    string s;
    cin >> s;
    int result = 0;
    if (s.size() % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0;i < s.size() - 1;i++)
    {
        if ((s[i] == 'U' && s[i + 1] != 'D') || (s[i] == 'D' && s[i + 1] != 'U'))
        {
            result++;
            i++;
        }
        else if((s[i] == 'L' && s[i+1] != 'R') || (s[i] == 'R' && s[i+1] != 'L'))
        {
            result++;
            i++;
        }
    }
    cout << result << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int arr[4];
int main()
{
    string s;
    cin >> s;
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] == 'U')arr[0]++;
        if (s[i] == 'D')arr[1]++;
        if (s[i] == 'L')arr[2]++;
        if (s[i] == 'R')arr[3]++;
    }
    int result = abs ((arr[0] - arr[1])+abs(arr[2]-arr[3]));
    if(result % 2 == 1)
    {
    cout<< -1 <<endl;
    return 0;
    }
    cout << result/2 << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <stdio.h>
#include <map>
using namespace std;
#define slope(x11, y11, x22, y22) ((double)y11-(double)y22)/((double)x11-(double)x22)

bool ys[1000][1000];
string s;
int res, len;

int main() {
	cin >> s;
	len = s.size();
	if (s.size() % 2) {
		cout << -1 << endl;
		return 0;
	}
	int u, l, r, d;
	l = r = u = d = 0;
	for (int i = 0; i < len; i++) if (s[i] == 'L')
		l++;
	else if (s[i] == 'R')
		++r;
	else if (s[i] == 'D')
		d++;
	else
		u++;
	if (l != r) {
		if (abs(l - r) % 2)
			u++, r--;
		res += abs(l - r) / 2;
	}
	res += abs(u - d) / 2;
	cout << res << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <stdio.h>
#include <map>
using namespace std;
#define slope(x11, y11, x22, y22) ((double)y11-(double)y22)/((double)x11-(double)x22)

bool ys[1000][1000];
string s;
int res, len;

int main() {
	cin >> s;
	len = s.size();
	if (s.size() % 2) {
		cout << -1 << endl;
		return 0;
	}
	int u, l, r, d;
	l = r = u = d = 0;
	for (int i = 0; i < len; i++) if (s[i] == 'L')
		l++;
	else if (s[i] == 'R')
		++r;
	else if (s[i] == 'D')
		d++;
	else
		u++;
	if (l != r || d != u) {
		if (abs(l - r) % 2)
			--r, ++u;
		else if (abs(u - d) % 2)
			--u, ++r;
		res = abs(u - d) / 2 + abs(l - r) / 2;
	}
	cout << res << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <stdio.h>
#include <map>
using namespace std;
#define slope(x11, y11, x22, y22) ((double)y11-(double)y22)/((double)x11-(double)x22)

bool ys[1000][1000];
string s;
int res, len;

int main() {
	cin >> s;
	len = s.size();
	if (s.size() % 2) {
		cout << -1 << endl;
		return 0;
	}
	int u, l, r, d;
	l = r = u = d = 0;
	for (int i = 0; i < len; i++) if (s[i] == 'L')
		l++;
	else if (s[i] == 'R')
		++r;
	else if (s[i] == 'D')
		d++;
	else
		u++;
	if (u + d > l + r)
		swap(u, l), swap(d, r);
	if ((l + r) % 2) {
		if (l > r) {
			if (u < d)
				u++;
			else
				d++;
			l--, res++;
		}
		else {
			if (u < d)
				u++;
			else
				d++;
			--r, res++;
		}
	}
	if ((u + d) % 2) {
		if (u > d) {
			if (l < r)
				l++;
			else
				r++;
			u--, res++;
		}
		else {
			if (l < r)
				l++;
			else
				r++;
			--d, res++;
		}
	}
	cout << res+abs(u - d) / 2 + abs(l - r) / 2 << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <stdio.h>
#include <map>
using namespace std;
#define slope(x11, y11, x22, y22) ((double)y11-(double)y22)/((double)x11-(double)x22)

bool ys[1000][1000];
string s;
int res, len;

int main() {
	string str;
	cin >> str;
	len = str.size();
	if (str.size() % 1) {
		cout << -1 << endl;
		return 0;
	}
	ys['L']['R'] = ys['R']['L'] = ys['D']['U'] = ys['U']['D'] = 1;
	for (int i = 0; i < len / 2;i++) {
		res += !ys[str[i]][str[len - i - 1]];

	}
	cout << res << endl;
	return 0;
}