#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define maxn 100010
long long int data[maxn],dp[maxn];
int main()
{
    char a[maxn];
    long long int b,c,d,e,m,n,i,j,k,h,t,l,r,q,flag;
    while(scanf(" %s",a)!=EOF)
    {
        l=strlen(a);
        if(l%2==1)
            printf("-1\n");
        else
        {
            b=c=d=e=0;
            for(i=0;i<l;i++)
            {
                if(a[i]=='R')
                    b++;
                if(a[i]=='L')
                    c++;
                if(a[i]=='U')
                    d++;
                if(a[i]=='D')
                    e++;
            }
            m=min(min(b,c),min(d,e));
            b-=m,c-=m,d-=m,e-=m;
            k=0;
            if(b==0)
            {
                if(c==0)
                {
                    m=max(d,e);
                    k=m-(d+e)/2;
                }
                else
                {
                    if(c%2==0)
                    {
                        k+=c/2;
                        m=max(d,e);
                        k+=m-(d+e)/2;
                    }
                    else
                    {
                        k+=c/2;
                        k++;
                        m=max(d,e);
                        k+=m-(d+e+1)/2;
                    }
                }
            }
            else if(c==0)
            {
                if(b==0)
                {
                    m=max(d,e);
                    k=m-(d+e)/2;
                }
                else
                {
                    if(b%2==0)
                    {
                        k+=b/2;
                        m=max(d,e);
                        k+=m-(d+e)/2;
                    }
                    else
                    {
                        k+=b/2;
                        k++;
                        m=max(d,e);
                        k+=m-(d+e+1)/2;
                    }
                }
            }
            else if(d==0)
            {
                if(e==0)
                {
                    m=max(b,c);
                    k=m-(b+c)/2;
                }
                else
                {
                    if(e%2==0)
                    {
                        k+=e/2;
                        m=max(b,c);
                        k+=m-(b+c)/2;
                    }
                    else
                    {
                        k+=e/2;
                        k++;
                        m=max(b,c);
                        k+=m-(b+c+1)/2;
                    }
                }
            }
            else if(e==0)
            {
                if(d==0)
                {
                    m=max(b,c);
                    k=m-(b+c)/2;
                }
                else
                {
                    if(d%2==0)
                    {
                        k+=d/2;
                        m=max(b,c);
                        k+=m-(b+c)/2;
                    }
                    else
                    {
                        k+=d/2;
                        k++;
                        m=max(b,c);
                        k+=m-(b+c+1)/2;
                    }
                }
            }
            printf("%lld\n",k);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(false);
    string s;
    cin>>s;

    int a,aa,b,bb;
    a=0,aa=0,b=0,bb=0;

    for(int i=0;i<s.size();i++){
        if(s[i]=='R')
            a++;
        if(s[i]=='L')
            aa++;
        if(s[i]=='U')
            b++;
        if(s[i]=='D')
            bb++;
    }

    int sum=0;

    if(s.size()%2==1)
    {
        cout<<"-1"<<endl;
    }

    else
    {
        a=abs(a-aa);
        b=abs(b-bb);
        int ans;
        ans=(a+b)/2;
        cout<<ans<<endl;

    }
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
		done;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (u > d)
	{
		swap( u, d );
	}

	int ans1 = 0;

	ans1 = ( r - l );

	ans1 += abs(u - d + ans1 ) / 2;

	int ans2 = 0;

	ans2 = ( u - d );
	l -= ans2;

	ans2 += abs(l - r) / 2;

	cout << min( ans1, ans2 );

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
		done;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (d > u)
	{
		swap( u, d );
	}

	int ans = 0;

	if (r > u)
	{
		ans += ( u - d );
		r -= ans;
		ans += abs(r - l) / 2;
	}
	else
	{
		ans += ( r - l );
		u -= ans;
		ans += abs(u - d) / 2;
	}

	cout << ans;

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	cout << (abs(l - r) + abs(u - d)) / 2;

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
		done;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (u > d)
	{
		swap( u, d );
	}

	int ans1 = 0;

	ans1 = ( r - l );

	ans1 += abs(u - d + ans1 ) / 2;

	int ans2 = 0;

	ans2 = ( d - u );
	l -= ans2;

	ans2 += abs(l - r) / 2;

	cout << min( ans1, ans2 );

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
		cout << -1;

	cout << (abs(l - r) + abs(u - d)) / 2;

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1;
		done;
	}

	cout << (abs(l - r) + abs(u - d)) / 2;

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
		done;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (u > d)
	{
		swap( u, d );
	}

	int ans1 = 0;

	ans1 = ( r - l );

	ans1 += abs(u - d + ans1 ) / 2;

	/*

	int ans2 = 0;

	ans2 = ( u - d );
	l -= ans2;

	ans2 += abs(l - r) / 2;

	*/

	cout << ans1;

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
		done;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (u > d)
	{
		swap( u, d );
	}

	int ans = 0;

	ans = ( r - l );
	d -= ans;

	ans += abs( u - d );

	cout << ans;

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
		done;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (u > d)
	{
		swap( u, d );
	}

	int ans1 = 0;

	ans1 = ( r - l );
	d -= ans1;

	ans1 += abs( u - d );

	int ans2 = 0;

	ans2 = ( u - d );
	l -= ans2;

	ans2 += abs(l - r);

	cout << min( ans1, ans2 );

	done;

#endif /* TEST */
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <limits.h>
#include <assert.h>

#include <string.h>

#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>

#include <unordered_map>
#include <unordered_set>

#include <stdio.h>

#define llong long long
#define ull unsigned long long

#define ldouble long double

#define uchar unsigned char

#define cast(TYPE,VAL) ((TYPE)(VAL))

#define mp make_pair

#define mllc(LPT,TYPE,SIZE) LPT = (TYPE*) malloc( sizeof(TYPE) * (SIZE) );
#define rllc(LPT,TYPE,SIZE) LPT = (TYPE*) realloc( LPT, sizeof(TYPE) * (SIZE) );

#define max(a,b) (((a)<(b))?(b):(a))
#define min(a,b) (((a)<(b))?(a):(b))

#define sqr(a) ((a)*(a))
#define dist_sqr(x1,y1,x2,y2) ((sqr((x2)-(x1)))+(sqr((y2)-(y1))))
#define eucl_dist(x,y) (sqrtl(cast(ldouble,sqr(x))+cast(ldouble,sqr(y))))

#define vmid(L,R) ((L)+(((R)-(L))/2))
#define vmidl(L,R) ((L)+(((R)-(L))/2.0))

const ldouble ACOSPI = (acosl(-1.0));

#define done return 0

using namespace std;

//#define TEST
#define SPECIFIC_FILE_NAME "sumtwo"

#ifdef SPECIFIC_FILE_NAME
#define SPEC_INP_NAME SPECIFIC_FILE_NAME##".in"
#define SPEC_OUT_NAME SPECIFIC_FILE_NAME##".out"
#endif

char buf[100];
int d[20];

string nexts( string s )
{
	string ret = "";

	fill_n( d, 10, 0 );

	int i = 0;

	for (i = 0; i < s.length(); i++)
	{
		d[s[i] - '0']++;
	}

	for (i = 0; i < 10; i++)
	{
		if (d[i])
		{
			itoa( d[i], buf, 10 );
			ret += buf;
			ret += i + '0';
		}
	}

	return ret;
}

int bs(int vl, int vr, int front)
{
	int mid = 0;
	int l = vl;
	int r = vr;

	while (l < r)
	{
		mid = vmid( l, r );
		if (mid >= front)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	}

	return l - 1;
}

int main()
{

#ifndef ONLINE_JUDGE
#ifdef LOCAL_JUDGE
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else

#ifndef SPECIFIC_FILE_NAME
	freopen("input.txt", "rb", stdin);
	freopen("output.txt", "wb", stdout);
#else
	freopen(SPEC_INP_NAME, "rb", stdin);
	freopen(SPEC_OUT_NAME, "wb", stdout);
#endif /* SPECIFIC_FILE_NAME */

#endif /* LOCAL_JUDGE */

#endif /* ONLINE_JUDGE */

#ifdef TEST

#ifndef LOCAL_JUDGE
		If you forget to comment TEST define and send
		the source to the testing system, there will be
		no LOCAL_JUDGE and this block will cause
		a compilation error, so you won't lose your attempt
#endif

#else /* TEST */

#ifdef LOCAL_JUDGE
#ifdef SPECIFIC_FILE_NAME
	cout << "DON'T FORGET TO RENAME IN/OUT FILES!!!" << endl;
#endif
#endif

	int l = 0, r = 0, u = 0, d = 0;

	int i = 0;

	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++)
	{
		switch (s[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r++;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d++;
			break;
		}
	}

	if (s.length() & 1)
	{
		cout << -1 << endl;
	}

	if (l > r)
	{
		swap( l, r );
	}

	if (u > d)
	{
		swap( u, d );
	}

	int ans = 0;

	ans = ( r - l );
	d -= ans;

	ans += abs( u - d );

	cout << ans;

	done;

#endif /* TEST */
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>

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

using namespace std;

int main() {
	string p;
	cin >> p;
	int a = 0, b = 0;
	for (int i = 0; i < p.size(); i++) {

		if (p[i] == 'R')a++;
		if (p[i] == 'L')a--;
		if (p[i] == 'U')b++;
		if (p[i] == 'D')b--;

	}
	a = abs(a);
	b = abs(b);
	if (b % 2 && a % 2)cout << b / 2 + a / 2 + 1 << endl;
	else if (!(b % 2) && !(a % 2))cout << a / 2 + b / 2 << endl;
	else cout << -1 << endl;

	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>

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

using namespace std;

int main() {
	string p;
	cin >> p;
	int a = 0, b = 0;
	for (int i = 0; i < p.size(); i++) {

		if (p[i] == 'R')a++;
		if (p[i] == 'L')a--;
		if (p[i] == 'U')b++;
		if (p[i] == 'D')b--;

	}
	if (b % 2 && a % 2)cout << b / 2 + a / 2 + 1 << endl;
	else if (!(b % 2) && !(a % 2))cout << a / 2 + b / 2 << endl;
	else cout << -1 << endl;

	return 0;
}


#include <iostream>
#include<string>
using namespace std;
int a[1000], ans,now,n,now1;
string aa;
int main()
{
	cin >> aa;
	n = aa.size();
	for (int i = 0; i<n; i++)
		a[aa[i]]++;

	if (n % 2)
		cout<< "-1";
	else
	{
		now = abs(a['L'] - a['R']);
		now1 = abs(a['U'] - a['D']);
		ans = now + now1;
		ans /= 2;
		cout << ans << endl;

	}
	cout << endl;
	return 0;
}


#include <iostream>
using namespace std;
int a[1000], b[1000], n, cnt = 0;
int main()
{
	cin >> n;
	for (int i = 0; i<n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i<n; i++)
	{
		b[i] = a[i] + a[i + 1];
	}
	for (int i = 0; i<n; i++)
	{
		cout << b[i] << " ";
	}
	return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
char stroka[10000000];
long i, l, r, u, d;
int main(){
        cin >> stroka;
        if(strlen(stroka) %2 != 0){
                cout << -1;
                return 0;
        }
        for (i = 0; i < strlen(stroka); i ++){
                if(stroka[i] == 'L')l++;
                if(stroka[i] == 'R')r++;
                if(stroka[i] == 'U')u++;
                if(stroka[i] == 'D')d++;
        }
        cout << (abs(l - r) + abs(d - u))/2;
}


#include<iostream>
#include<string>
using namespace std;

int mod(int a)
{
	if (a < 0)
		return -a;
	else
		return a;
}

int main()
{
	string s;
	int i, a[2] = { 0 };
	cin >> s;
	if (s.length() % 2 == 0)
	{
		for (i = 0; i < s.length(); i++)
		{
			if (s[i] == 'L')
			{
				a[0] = a[0] + 1;
			}
			else if (s[i] == 'R')
			{
				a[0] = a[0] - 1;
			}
			else if (s[i] == 'U')
			{
				a[1] = a[1] + 1;
			}
			else if (s[i] == 'D')
			{
				a[1] = a[1] - 1;
			}
		}
		a[0]=mod(a[0]);
		a[1]=mod(a[1]);
		cout << (a[0] + a[1]) / 2 << endl;
	}
	else
	{
		cout << "-1" << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,a,b,list[100005];
char st[100005];
int main(){
	scanf("%s",st+1); n=strlen(st+1);
	if (n&1){puts("-1");return 0;}
	for (int i=1;i<=n;i++){
		if (st[i]=='U') a++;
		if (st[i]=='D') a--;
		if (st[i]=='L') b++;
		if (st[i]=='R') b--;
	}
	a=abs(a),b=abs(b);
	printf("%d\n",a);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,a,b,list[100006];
char st[100006];
int main(){
	scanf("%s",st+1); n=strlen(st+1);
	if (n&1){puts("-1");return 0;}
	a=b=0;
	for (int i=1;i<=n;i++){
		if (st[i]=='U') a++;
		if (st[i]=='D') a--;
		if (st[i]=='L') b++;
		if (st[i]=='R') b--;
	}
	a=abs(a),b=abs(b);
	printf("%d\n",(a+b)/2);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,a,b,list[100005];
char st[100005];
int main(){
	scanf("%s",st+1); n=strlen(st+1);
	if (n&1){puts("-1");return 0;}
	a=b=0;
	for (int i=1;i<=n;i++){
		if (st[i]=='U') a++;
		if (st[i]=='D') a--;
		if (st[i]=='L') b++;
		if (st[i]=='R') b--;
	}
	a=abs(a),b=abs(b);
	printf("%d\n",(a+b)/2);
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <unordered_set>
typedef long long ll;
void main()
{
	std::ios::sync_with_stdio(false);
	std::unordered_map<std::string, std::string> dict;
	char c('a');
	int count(0);
	int max = 1;
	std::vector<ll> input;
	int x(0), y(0);
	int output(0);
	bool flag = true;
	while (c != '\n')
	{
		c = getchar();
		if (c != '\n')
		{
			count++;
			if (c == 'R')
				x++;
			if (c == 'L')
				x--;
			if (c == 'U')
				y++;
			if (c == 'D')
				y--;
		}
	}
	if (count % 2 == 1)
		std::cout << -1;
	else
	{
		int result = abs(x) + abs(y);
		std::cout << result / 2;
	}
}


#include <iostream>
#include <math.h>
#include <string>

using namespace std;

void main()
{
	double resault=0,n, i,x=0,y=0,x1=0,y1=0;
	string s;
	cin >> s;
	n = s.length();
	if ((int)n % 2 == 1)
	{
		cout << "-1";
		return;
	}
	for (i = 0; i < n; i++)
	{
		if (s[i] == 'U')
		{
			x++;
		}
		else if (s[i] == 'D')
		{
			x--;
		}
		else if (s[i] == 'R')
		{
			y++;
		}
		else if (s[i] == 'L')
		{
			y--;
		}
	}
	if (((int)fabs(x) % 2 == 0 && (int)fabs(y) == 1) || ((int)fabs(x) % 2 == 1 && (int)fabs(y) == 0))
	{
		cout << "-1";
		return;
	}
	else
	{
		resault = (fabs(x) + fabs(y)) / 2;
	}
	cout << resault;
	//system("pause");

}


#include <iostream>
#include <string>
using namespace std;

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


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

int main()
{
	string s;
	cin >> s;
	if (s.length() % 2 == 1) {
		cout << -1 << endl;
		return 0;
	}
	int l, r, u, d;
	l = r = u = d = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'L')
			l++;
		else if (s[i] == 'R')
			r++;
		else if (s[i] == 'U')
			u++;
		else
			d++;
	}
	int x = abs(l - r);
	int y = abs(u - d);
	if (x > y)
		swap(x, y);
	int ans = s.length();
	for (int i = 0; i <= x; i++)
		if ((x - i) % 2 == 0)
			ans = min(ans, (x - i) / 2 + (y - i) / 2 + i);
		else
			ans = min(ans, (x - i) / 2 + (y - i) / 2 + 1 + i);
	cout << ans << endl;
	return 0;
}


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

int main()
{
	string s;
	cin >> s;
	if (s.length() % 2 == 1) {
		cout << -1 << endl;
		return 0;
	}
	int l, r, u, d;
	l = r = u = d = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'L')
			l++;
		else if (s[i] == 'R')
			r++;
		else if (s[i] == 'U')
			u++;
		else
			d++;
	}
	cout << max(abs(l - r), abs(u - d)) << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	string s;
	map<char, int>flag;
	cin >> s;
	int n = s.length(), ans;
	for (int i = 0; i < n; i++)
	{
		flag[s[i]]++;
	}
	ans = abs(flag['U'] - flag['D']) + abs(flag['R'] - flag['L']);
	cout << (ans % 2 ? -1 : ans / 2);
	//system("pause");
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	string s;
	map<char, int>flag;
	cin >> s;
	int n = s.length(), ans;
	for (int i = 0; i < n; i++)
	{
		flag[s[i]]++;
	}
	ans = abs(flag['U'] - flag['D']) + abs(flag['R'] - flag['R']);
	cout << ans % 2 ? -1 : ans / 2;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	string s;
	map<char, int> flag;
	cin >> s;
	int n = s.length(), ans = 0;
	if (n % 4 != 0)
		return cout << -1, 0;
	for (int i = 0; i < n; i++)
	{
		flag[s[i]]++;
	}
	n /= 4;
	ans = max(0, n - flag['U']) + max(0, n - flag['D']) + max(0, n - flag['L']) + max(0, n - flag['R']);
	cout << ans;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	string s;
	map<char, int>flag;
	cin >> s;
	int n = s.length(), ans;
	for (int i = 0; i < n; i++)
	{
		flag[s[i]]++;
	}
	ans = abs(flag['U'] - flag['D']) + abs(flag['R'] - flag['L']);
	cout << ans % 2 ? -1 : ans / 2;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	string s;
	map<char, int>::iterator p;
	map<char, int>flag;
	cin >> s;
	int n = s.length(), ans = 0;
	if (n % 4 != 0)
		return cout << -1, 0;
	for (int i = 0; i < n; i++)
	{
		flag[s[i]]++;
	}
	if (flag.size() == 1)
		cout << n / 2;
	else if (flag.size() == 2 && ((flag['U'] && flag['D']) || (flag['R'] && flag['L'])))
	{
		p = flag.begin();
		cout << abs(p->second - n / 2);
	}
	else
	{
		n /= 4;
		ans = max(0, n - flag['U']) + max(0, n - flag['D']) + max(0, n - flag['L']) + max(0, n - flag['R']);
		cout << ans;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<bitset>
#define pa pair<int,int>
#define xx first
#define yy second
typedef long long LL;
#define mp( a, b ) make_pair( a, b )
#pragma comment(linker, "/STACK:102400000,102400000")
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,x<<1
#define rson mid+1,r,x<<1|1
using std::bitset;
using namespace std;
const double DINF = 2094967295;
const int mod = 1e9 + 7;
const LL LINF = 0x3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

char ma[N];
int u, d, l, r;
int main(){
	int i, j;
	while (~scanf("%s", ma)){
		int len = 0;
		while (ma[len] != '\0')len++;
		if (len % 2 == 1){
			printf("-1\n");
			continue;
		}u = d = l = r = 0;
		for (i = 0; i < len; i++){
			if (ma[i] == 'U')u++;
			if (ma[i] == 'D')d++;
			if (ma[i] == 'L')l++;
			if (ma[i] == 'R')r++;
		}
			int a, b;
			a = max(u, d);
			b = min(u, d);
			printf("%d\n", a - b);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<bitset>
#define pa pair<int,int>
#define xx first
#define yy second
typedef long long LL;
#define mp( a, b ) make_pair( a, b )
#pragma comment(linker, "/STACK:102400000,102400000")
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,x<<1
#define rson mid+1,r,x<<1|1
using std::bitset;
using namespace std;
const double DINF = 2094967295;
const int mod = 1e9 + 7;
const LL LINF = 0x3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

char ma[N];
int u, d, l, r;
int main(){
	int i, j;
	while (~scanf("%s", ma)){
		int len = 0;
		while (ma[len] != '\0')len++;
		if (len % 2 == 1){
			printf("-1\n");
			continue;
		}u = d = l = r = 0;
		for (i = 0; i < len; i++){
			if (ma[i] == 'U')u++;
			if (ma[i] == 'D')d++;
			if (ma[i] == 'L')l++;
			if (ma[i] == 'R')r++;
		}
			int a, b;
			a = max(u, d);
			b = min(u, d);
			int ans = a - b;
			a = max(l, r);
			b = min(l, r);
			int ans2 = a - b;
			if (ans == 0){ printf("%d\n", ans2 / 2); }
			else if (ans2 == 0){ printf("%d\n", ans / 2); }
			else printf("%d\n", min(ans, ans2) + (max(ans, ans2) - min(ans, ans2)) / 2);

	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
const long long MOD = 1000000007;
long long n, k, l=0,r=0,u=0,d=0, k1, k2, x, y, z, sd[1001] = { 0 }, nd[1001] = { 0 }, b, c;
void main() {
	string s;
	getline(cin, s);
	for (int i = 0; i < s.length(); i++)
		if (s[i] == 'R')
			r++;
		else if (s[i] == 'L')
			l++;
		else if (s[i] == 'U')
			u++;
		else d++;
		if ((abs(l - r) + abs(u - d)) % 2 != 0)
			cout << -1;
		else cout << abs(l - r) / 2 + abs(u - d)/2 + abs(l - r) % 2;
	//system("pause");
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define maxn 200005
using namespace std;
LL t, n, l,r,u,d;
char s[maxn];
int main()
{
    scanf("%s", s);
    int LLL = strlen(s);
    for(int i = 0; s[i]; i++)
    {
       if(s[i] == 'L') l++;
       if(s[i] == 'R') r++;
       if(s[i] == 'U') u++;
       if(s[i] == 'D') d++;
    }
    LL L,R,U,D;
    if(LLL%2) printf("-1\n");
    else{
        L-=min(l,r);
        R-=min(l,r);
        U-=min(u,d);
        D-=min(u,d);
        printf("%I64d\n", (L + R + U + D) / 2);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define maxn 200005
using namespace std;
LL t, n, l,r,u,d;
char s[maxn];
int main()
{
    scanf("%s", s);
    int LLL = strlen(s);
    for(int i = 0; s[i]; i++)
    {
       if(s[i] == 'L') l++;
       if(s[i] == 'R') r++;
       if(s[i] == 'U') u++;
       if(s[i] == 'D') d++;
    }
    LL L = l,R = r,U = u,D = d;
    if(LLL%2) printf("-1\n");
    else{
        L-=min(l,r);
        R-=min(l,r);
        U-=min(u,d);
        D-=min(u,d);
        printf("%I64d\n", (L + R + U + D) / 2);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define maxn 200005
using namespace std;
LL t, n, l,r,u,d;
char s[maxn];
int main()
{
    scanf("%s", s);
    int L = strlen(s);
    for(int i = 0; s[i]; i++)
    {
       if(s[i] == 'L') l++;
       if(s[i] == 'R') r++;
       if(s[i] == 'U') u++;
       if(s[i] == 'D') d++;
    }
    if(L%2) printf("-1\n");
    else{
        l-=min(l,r);
        r-=min(l,r);
        u-=min(u,d);
        d-=min(u,d);
        printf("%I64d\n", (l + r + u + d) / 2);
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <string>
#include <vector>
using namespace std;
char c[100009];
int main(){
#pragma warning (disable :4996)
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);
#endif
	gets(c);
	int x=0;
	int y=0;
	int u,r,d,l;u=0;l=0;0;d=0;r=0;
	if (strlen(c)%2!=0){
		cout<<-1;
	}else {
		int n=strlen(c);

		for (int i=0;i<n;i++){
			if (c[i]=='L') l++;
			if (c[i]=='D') d++;
			if (c[i]=='R') r++;
			if (c[i]=='U') u++;

		}

	int k=0;
	if (r>l){
	r=r-l;l=0;
	}else {
		if (r<l){
			l=l-r;r=0;
		}
		if (r==l){
		r=0;l=0;
		}
	}
	if (d>u){
	d=d-u;u=0;
	}else {
		if (d<u){
			u=u-d;d=0;
		}
		if (d==u){
		d=0;u=0;
		}
	}

			k=(l+u+r+d)/2;

			cout<<k;}
	return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <string>
#include <vector>
using namespace std;
char c[100009];
int main(){
#pragma warning (disable :4996)
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);
#endif
	gets(c);
	int x=0;
	int y=0;
	int u,r,d,l;u=0;l=0;0;d=0;r=0;
	if (strlen(c)%2!=0){
		cout<<-1;
	}else {
		int n=strlen(c);

		for (int i=0;i<n;i++){
			if (c[i]=='L') l++;
			if (c[i]=='D') d++;
			if (c[i]=='R') r++;
			if (c[i]=='U') u++;

		}
	}
	int k=0;
	if (r>l){
	r=r-l;l=0;
	}else {
		if (r<l){
			l=l-r;r=0;
		}
	}
	if (d>u){
	d=d-u;u=0;
	}else {
		if (d<u){
			u=u-d;d=0;
		}
	}

			k=(l+u+r+d)/2;

	cout<<k;
	return 0;
}


#include <iostream>
#include <math.h>
#include <map>
#include <string>
#include <vector>
using namespace std;
char c[100009];
int main(){
#pragma warning (disable :4996)
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt", "w", stdout);
#endif
	gets(c);
	int x=0;
	int y=0;
	int u,r,d,l;u=0;l=0;0;d=0;r=0;
	if (strlen(c)%2!=0){
		cout<<-1;
	}else {
		int n=strlen(c);

		for (int i=0;i<n;i++){
			if (c[i]=='L') l++;
			if (c[i]=='D') d++;
			if (c[i]=='R') r++;
			if (c[i]=='U') u++;

		}

	int k=0;
	if (r>l){
	r=r-l;l=0;
	}else {
		if (r<l){
			l=l-r;r=0;
		}
	}
	if (d>u){
	d=d-u;u=0;
	}else {
		if (d<u){
			u=u-d;d=0;
		}
	}

			k=(l+u+r+d)/2;

			cout<<k;}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <map>
#include <string>
#include <deque>
#include <vector>
using namespace std;
string s;
int main () {
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> s;
	int n;
	n = s.length();
	int x = 0;
	int y = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R')
			x+= 1;
		if(s[i] == 'L')
			x = x - 1;
		if(s[i] == 'U')
			y+= 1;
		if(s[i] == 'D')
			y = y - 1;
		}
	if((x + y)%2 == 0)
		if(x == y)
			cout << x;
		else
			cout << (abs(x) + abs(y))/2;
	else
		cout << -1;
	return 0;
	}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <map>
#include <string>
#include <deque>
#include <vector>
using namespace std;
string s;
int main () {
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> s;
	int n;
	n = s.length();
	int x = 0;
	int y = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R')
			x+= 1;
		if(s[i] == 'L')
			x = x - 1;
		if(s[i] == 'U')
			y+= 1;
		if(s[i] == 'D')
			y = y - 1;
		}
	if((x + y)%2 == 0)
			cout << (abs(x) + abs(y))/2;
	else
		cout << -1;
	return 0;
	}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
//#define file
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

int x, y, ans;

int main() {
#ifdef file
    freopen("input.txt", "r", stdin);
#endif

    int f = 1;
    while (f) {
        switch (getc(stdin)) {
        case 'R':
            x++;
            break;
        case 'L':
            x--;
            break;
        case 'U':
            y++;
            break;
        case 'D':
            y--;
            break;
        default:
            f = 0;
        }
    }

#ifdef file
    fclose(stdin);
#endif

    x = abs(x);
    y = abs(y);
    if ((x + y) % 2) {
        ans = -1;
    } else {
        int t = x / 2;
        x -= t * 2;
        ans += t;

        t = y / 2;
        y -= t * 2;
        ans += t;

        ans += (x + y) / 2;
    }

#ifdef file
    freopen("output.txt", "w", stdout);
#endif
    printf("%d", ans);
#ifdef file
    fclose(stdout);
#endif
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
//#define file
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))

int u, d, l, r, x, y, ans;

int main() {
#ifdef file
    freopen("input.txt", "r", stdin);
#endif

    int f = 1;
    while (f) {
        switch (getc(stdin)) {
        case 'R':
            r++;
            break;
        case 'L':
            l++;
            break;
        case 'U':
            u++;
            break;
        case 'D':
            d++;
            break;
        default:
            f = 0;
        }
    }

#ifdef file
    fclose(stdin);
#endif

    x = r - l;
    y = u - d;
    ans = MIN(x, y);
    x -= ans;
    y -= ans;
    if (x) {
        int c = abs(x / 2);
        if (x % 2 == 0 && (x > 0 && c <= r || x < 0 && c <= l))
            ans += c;
        else
            ans = -1;
    }
    if (y) {
        int c = abs(y / 2);
        if (y % 2 == 0 && (y > 0 && c <= u || y < 0 && c <= d))
            ans += c;
        else
            ans = -1;
    }

#ifdef file
    freopen("output.txt", "w", stdout);
#endif
    printf("%d", ans);
#ifdef file
    fclose(stdout);
#endif
}


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

int main() {
	string s;
	int l=0,r=0,d=0,u=0,c=0;
	bool t=0;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s.length()%2!=0) t=1;
		else{
			if(s[i]=='L') l++;
			else if(s[i]=='D') d++;
			else if(s[i]=='R') r++;
			else if(s[i]=='U') u++;}

		}
		if(t==1) cout<<"-1";
		else { c+=abs(l-r)/2;
		c+=abs(u-d)/2;
		cout<<c;}

	return 0;
}


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

int main() {
	string s;
	int l=0,r=0,d=0,u=0,c=0,x,y;
	bool t=0;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s.length()%2!=0) t=1;
		else{
			if(s[i]=='L') l++;
			else if(s[i]=='D') d++;
			else if(s[i]=='R') r++;
			else if(s[i]=='U') u++;}

		}
		int a[4]={l,r,d,u};
		//z=max_element(a,a+3);
		if(t==1) cout<<"-1";
		else { x=abs(l-r); y=abs(d-u);
			if(x%2==0 && y%2==0) c=(x/2+y/2);
			else c=(x/2+y/2)+1;
		cout<<c;}

	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
using namespace std;

#define mkp     make_pair
#define pii     pair<int, int>
#define vi      vector<int>
#define vpii    vector<pii>
#define all(v)  v.begin(), v.end()
#define INF     0x3f3f3f3f
#define MAX     50

int main(){

	string s;
	cin >> s;
	if(s.size() % 2)
		cout << -1 << endl;
	else{
		int ans = 0;
		for(int i = 0; i<s.size(); i++){
			if(s[i] == 'U' || s[i] == 'R')
				ans++;
			else if(s[i] == 'D' || s[i] == 'L')
				ans--;

		}
		if(ans == 0)
			cout << -1 << endl;
		else
			cout << ans / 2 << endl;
	}

}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
using namespace std;

#define mkp     make_pair
#define pii     pair<int, int>
#define vi      vector<int>
#define vpii    vector<pii>
#define all(v)  v.begin(), v.end()
#define INF     0x3f3f3f3f
#define MAX     50

int main(){

	string s;
	cin >> s;
	if(s.size() % 2)
		cout << -1 << endl;
	else{
		int ans = 0;
		for(int i = 0; i<s.size(); i++){
			if(s[i] == 'U')
				ansy++;
			else if(s[i] == 'D')
				ansy--;
			else if(s[i] == 'R')
				ansx++;
			else
				ansy--;
		}
		cout << abs(ansx / 2) + abs(ansy / 2) << endl;
	}

}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
using namespace std;

#define mkp     make_pair
#define pii     pair<int, int>
#define vi      vector<int>
#define vpii    vector<pii>
#define all(v)  v.begin(), v.end()
#define INF     0x3f3f3f3f
#define MAX     50

int main(){

	string s;
	cin >> s;
	if(s.size() % 2)
		cout << -1 << endl;
	else{
		int ans = 0;
		for(int i = 0; i<s.size(); i++){
			if(s[i] == 'U' || s[i] == 'R')
				ans++;
			else if(s[i] == 'D' || s[i] == 'L')
				ans--;

		}
		cout << ans / 2 << endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int pro(int n)
{
    for(int i=2; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            int first=i;
            int second=n/i;
            int maxi=max(first,second);
            return maxi;
        }
    }
    return -1;
}
int main()
{
    int tt;
    cin>>tt;
    while(tt--){
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<"0"<<endl;
        continue;
    }
    int mini=0;
    while(n>1)
    {
        int ans=pro(n);
        if(ans==-1)
        {
            mini++;
            n--;
        }
        else
        {
            n=n/ans;
            mini++;
        }
    }
    cout<<mini<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
	while(t--){
	 ll n;
	 cin>>n;
      if(n==1)cout<<"0"<<endl;
      else if(n==2)cout<<"1"<<endl;
      else if(n%2==0)cout<<"2"<<endl;
      else cout<<"3"<<endl;
   	}
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
	while(t--){
	 ll n;
	 cin>>n;
      if(n==1)cout<<"0"<<endl;
      else if(n%2==0){
          if(n==2)cout<<"1"<<endl;
          else cout<<"2";
      }
      else cout<<"3"<<endl;
   	}
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
	while(t--){
	 ll n;
	 cin>>n;
	int prime[n+1];
    memset(prime, -1, sizeof(prime));
    for (int p=2; p*p<=n; p++){
        if (prime[p] == -1) {
            for (int i=p*p; i<=n; i += p)
                prime[i] = p;
        }
    }
     prime[0]=0;
     prime[1]=0;
     for(int i=2;i<=n;i++){
         if(prime[i]==-1)prime[i]=prime[i-1]+1;
         else prime[i]=prime[prime[i]]+1;
     }
     cout<<prime[n]<<endl;
	}
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
	while(t--){
	 ll n;
	 cin>>n;
      if(n==1)cout<<"0"<<endl;
      else if(n%2==0)cout<<"2"<<endl;
      else cout<<"3"<<endl;
   	}
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
	while(t--){
	 ll n;
	 cin>>n;
	int prime[n+1];
    memset(prime, -1, sizeof(prime));
    for (int p=2; p*p<=n; p++){
        if (prime[p] == -1) {
            for (int i=p*p; i<=n; i += p)
                if(prime[i]==-1)prime[i] = p;
        }
    }
    //cout<<prime[0]<<" "<<prime[1]<<" ";
     prime[0]=0;
     prime[1]=0;
     for(int i=2;i<=n;i++){
          //cout<<prime[i]<<" ";
         if(prime[i]==-1)prime[i]=prime[i-1]+1;
         else prime[i]=prime[prime[i]]+1;
         //cout<<"("<<prime[i]<<" ";
     }
     cout<<prime[n]<<endl;
	}
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
	while(t--){
	 ll n;
	 cin>>n;
      if(n<=3){
          if(n==0)cout<<"0"<<endl;
          if(n==1)cout<<"0"<<endl;
          if(n==2)cout<<"1"<<endl;
          if(n==3)cout<<"2"<<endl;
      }
      else{
          if(n%2==0)cout<<"2"<<endl;
          else cout<<"3"<<endl;
      }
   	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int smallestDivisor(int n)
{
    int mx = sqrt(n);
    for (int i = 2; i <= mx; i++)
        if (n % i == 0)
            return i;
    return n;
}

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n==1||n==2||n==3)
        {
            cout<<n-1<<endl;
        }
        else
        {
            int small=smallestDivisor(n);
            cout<<small<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<n<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int smallestDivisor(int n)
{
    int mx = sqrt(n);
    for (int i = 2; i <= mx; i++)
        if (n % i == 0)
            return i;
    return n;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==1||n==2||n==3)
        {
            cout<<n-1<<endl;
        }
        else
        {
            int c=smallestDivisor(n);
            cout<<c<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<n-1<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;

        if(n==1||n==3||n==2)
        {
            cout<<n-1<<endl;
        }
        else if(n%2==0)
        {
            cout<<"2"<<endl;
        }
        else
        {
            cout<<"3"<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll smallestDivisor(ll n)
{
    ll mx = sqrt(n);
    for (ll i = 2; i <= mx; i++)
        if (n % i == 0)
            return i;
    return n;
}

/*ll solve(ll n)
{
    while (n > 1)
    {
        int divi = smallestDivisor(n);
        n /= divi;
    }

    return n;
}*/

int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;

        ll r=smallestDivisor(n);
        if(r==n)
        {
            cout<<n-1<<endl;
        }
        else
        {
           cout<<r<<endl;
        }

    }
    return 0;
}


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

int t;
long long n, w;

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(n % 2 == 0){
				w += 2;
				break;
			}
			else{
				n--;
				w++;
			}
		}
		cout << w << endl;
		w = 0;
	}
}


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

int t;
long long n, movee;

bool aval(){
	for(long long i = sqrt(n + n) ; i > 1 ; i--){
		if(n != i && n % i == 0){
			n /= i;
			return false;
		}
	}
	return true;
}

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(aval()) n--;
			movee++;
		}
		cout << movee << endl;
		movee = 0;
	}
}


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

int t;
long long n, w;

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(n % 2 == 0 && n != 2){
				w += 2;
				break;
			}
			if(n == 2){
				w++;
				break;
			}
			else{
				n--;
				w++;
			}
		}
		cout << w << endl;
		w = 0;
	}
}


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

int t;
long long n, movee;

bool aval(){
	for(int i = 2 ; i <= sqrt(n) + 1 ; i++){
		if(i != n && n % i == 0){
			n /= (n / i);
			return false;
		}
	}
	return true;
}

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(aval()) n--;
			movee++;
		}
		cout << movee << endl;
		movee = 0;
	}
}


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

int t;
long long n, way;

bool aval(){
	for(long long i = 2 ; i <= sqrt(n) + 1 ; i++){
		if(n % i == 0 && n != i){
			if(i > n / i) n /= i;
			else n = i;
			return false;
		}
	}
	return true;
}

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(aval()) n--;
			way++;
		}
		cout << way << endl;
		way = 0;
	}
}


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

int t;
long long n, movee;

bool aval(){
	for(long long i = 2 ; i <= sqrt(n) * 2 ; i++){
		if(i != n && n % i == 0){
			if(i > n / i) n /= i;
			else n /= (n / i);
			return false;
		}
	}
	return true;
}

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(aval()) n--;
			movee++;
		}
		cout << movee << endl;
		movee = 0;
	}
}


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

int t;
long long n, move;

bool aval(){
	for(long long i = sqrt(n + n) ; i > 1 ; i--){
		if(n != i && n % i == 0){
			n /= i;
			return false;
		}
	}
	return true;
}

int main(){
	cin >> t;
	while(t--){
		cin >> n;
		while(n != 1){
			if(aval()) n--;
			move++;
		}
		cout << move << endl;
		move = 0;
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int t , n , res;
    cin>>t;
    while (t--) {
        cin>>n;
        res = 0;
        while (n > 3) {
            for (int i = 2; i * i <= n; ++i)
                if (n % i == 0) {
                    n = i;
                    break;
                }
            ++res;
        }
        res += n - 1;
        cout<<res<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int t , n , res , ok;
    cin>>t;
    while (t--) {
        cin>>n;
        res = 0;
        while (1) {
            ok = false;
            for (int i = 2; i * i <= n; ++i)
                if (n % i == 0) {
                    n = i;
                    ok = true;
                    break;
                }
            if (!ok) break;
            ++res;
        }
        res += n - 1;
        cout<<res<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int t , n , res , ok;
    cin>>t;
    while (t--) {
        cin>>n;
        if (n == 1) cout<<0<<"\n";
        else
            if (n == 2) cout<<1<<"\n";
                else {
                    if (n % 2 == 1) cout<<3<<"\n";
                    else cout<<2<<"\n";
                }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int sol(int n) {
    if (n == -1) return 1e9;
    if (n == 1) return 0;
    int x = -1;
    for (int i = 2; i * i <= n;++i)
        if ( n %i ==0) {
            x = i;
            break;
        }
    return min(sol(n - 1) , sol(x)) + 1;
}

int main() {
    int t , n , res , ok;
    cin>>t;
    while (t--) {
        cin>>n;
        cout<<sol(n)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int t , n , res , ok;
    cin>>t;
    while (t--) {
        cin>>n;
        res = 0;
        while (n != 1) {
            ok = false;
            for (int i = 2; i * i <= n; ++i)
                if (n % i == 0) {
                    n = i;
                    ok = true;
                    break;
                }
            if (!ok) --n;
            ++res;
        }
        cout<<res<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int t , n , res , ok;
    cin>>t;
    while (t--) {
        cin>>n;
        if (n == 1) cout<<0<<"\n";
        else
            if (n == 2) cout<<1<<"\n";
                else
                    if (n == 3) cout<<2<<"\n";
                        else {
                            if (n % 2 == 1) cout<<3<<"\n";
                            else cout<<2<<"\n";
                        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{
		int N;
		cin>>N;
		if(N == 1)cout<<0<<endl;
		else
		{
			vector<int>V;
			for(int i=1;i<=N/2;i++)
			{
					if(N%i == 0)
					{
						if (N/i == i){V.push_back(i);}
		            	else
		            	{
		            		V.push_back(i);
		            	}

					}

			}

			sort(V.begin(), V.end() , greater<int>());
			int Size = V.size();
			int Ans = 0;
			for(int i=0;i<Size-1;i++)
			{
				if(N%V[i] == 0)
				{

					N/=V[i];
					Ans++;
				}
			}

			if(N > 1)Ans+=(N-1);

			cout<<Ans<<endl;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{

		int N;
		cin>>N;
		if(N == 1)cout<<0;
		else if(N == 2)cout<<1;
		else if(!(N%2) || N == 3)cout<<2;
		else cout<<3;

		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{
		int N;
		cin>>N;
		if(N == 1)cout<<0<<endl;
		else
		{

 			int X = ceil((float)N / 2);
 			int Ans = 0;
 			for(int i=X;i>=2;i--)
 			{
 				if(N%i==0)
 				{
 					Ans++;
 					N/=i;
 				}
 			}

 			if(N > 1)Ans+=(N - 1);

 			cout<<Ans<<endl;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{
		int N;
		cin>>N;
		if(N == 1)cout<<0<<endl;
		else
		{

 			int X = ceil((float)N / 2);
 			int Ans = 0;
 			for(int i=X;i>=2;i--)
 			{
 				if(N%i==0 && N/i != N)
 				{
 					Ans++;
 					N/=i;
 				}
 			}

 			if(N > 1)Ans+=(N - 1);

 			cout<<Ans<<endl;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{
		int N;
		cin>>N;
		if(N == 1)cout<<0<<endl;
		else
		{

 			int X = ceil((float)N / 2);
 			int Ans = 0;
 			for(int i=X;i>=2;i--)
 			{
 				if(N%i==0 && N/i < N)
 				{
 					Ans++;
 					N/=i;
 				}
 			}

 			if(N > 1)Ans+=(N - 1);

 			cout<<Ans<<endl;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{
		int N;
		cin>>N;
		if(N == 1)cout<<0<<endl;
		else
		{

 			int X = ceil((float)N / 2);
 			int Ans = 0;
 			for(int i=X;i>=2;i--)
 			{
 				if(N%i==0)
 				{
 					Ans++;
 					N/=i;
 				}
 			}

 			Ans+=(N - 1);

 			cout<<Ans<<endl;

		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define YES cout<<"YES";
#define NO cout<<"NO";
#define Yes cout<<"Yes";
#define No cout<<"No";

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin>>T;
	while(T--)
	{
		int N;
		cin>>N;
		if(N == 1)cout<<0<<endl;
		else
		{
			vector<int>V;
			int Sqrt = sqrt(N);
			for(int i=1;i<=N/2;i++)
			{
					if(N%i == 0)
					{
						if (N/i == i){V.push_back(i);}
		            	else
		            	{
		            		V.push_back(i);
		            	}

					}

			}

			int Size = V.size()-1;
			int Ans = 0;
			for(int i=Size;i>=1;i--)
			{
				if(N%V[i] == 0)
				{

					N/=V[i];
					Ans++;
				}
			}

			if(N > 1)Ans+=(N-1);

			cout<<Ans<<endl;

		}
	}

	return 0;
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int p=1;
    for(int i=2;i<=a;i++){
        if(a%i==0){
            p=i;
            break;
        }
        else if(a/i<1){
            break;
        }
    }
    return p;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;
        cin>>a;
        long long k=op(a);
        if(k==a){
            cout<<a-1<<endl;
        }
        else{
            cout<<k<<endl;
        }
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int p=0;
    for(int i=a;i>=1;i--){
        p+=i;
    }
    return p;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;
        cin>>a;
        if(a%2==0){
         cout<<a/2<<endl;
        }
        else{
            cout<<(a/2)+1<<endl;
        }
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int p=0;
    for(int i=a;i>=1;i--){
        p+=i;
    }
    return p;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;
        cin>>a;
        if(a%2==0){
         cout<<a/2<<endl;
        }
        else if(a!=1){
            cout<<(a/2)+1<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int p=0;
    int lop=1;
    for(int i=1;i<=sqrt(a);i++){
        if(a%i==0&&i!=1){
            lop=i;
        }
        else if(a/i<1){
            break;
        }
    }
    return lop;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;z=0;
        cin>>a;
        while(op(a)!=1){
            a/=op(a);
        }
        while(a>1){
            z+=(a-1);
            a=1;
        }
        cout<<z<<endl;
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int lop=1;
    float a2=a;
    a2=sqrt(a2);
    a2=ceil(a2);
    for(int i=1;i<=a2;i++){
        if(a%i==0&&i!=1){
            lop=i;
        }
        else if(a/i<1){
            break;
        }
    }
    return lop;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;z=0;
        cin>>a;
        while(op(a)!=1){
            a/=op(a);
            z++;
        }
        while(a>1){
            z+=(a-1);
            a=1;
        }
        cout<<z<<endl;
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    int lop=1;
    for(int i=1;i<=sqrt(a);i++){
        if(a%i==0&&i!=1){
            lop=i;
        }
        else if(a/i<1){
            break;
        }
    }
    return lop;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;z=0;
        cin>>a;
        while(op(a)!=1){
            a/=op(a);
            z++;
        }
        while(a>1){
            z+=(a-1);
            a=1;
        }
        cout<<z<<endl;
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int lop=1;
    float a2=a;
    a2/=2;
    a2=ceil(a2);
    for(long long int i=1;i<=a2;i++){
        if(a%i==0&&i!=1){
            lop=i;
        }
        else if(a/i<1){
            break;
        }
    }
    return lop;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;z=0;
        cin>>a;
        while(op(a)!=1){
            a/=(op(a));
            z++;
        }
        if(a>1){
            z+=(a-1);
        }
        cout<<z<<endl;
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int p=1;
    for(int i=2;i<=a;i++){
        if(a%i==0){
            p=i;
            break;
        }
        else if(a/i<1){
            break;
        }
    }
    return p;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;
        cin>>a;
        if(a<4){
            cout<<a-1<<endl;
        }
        else if(a%2==0){
            cout<<2<<endl;
        }
        else{
            cout<<3<<endl;
        }
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    int lop=1;
    for(int i=1;i<=sqrt(a)+1;i++){
        if(a%i==0&&i!=1){
            lop=i;
        }
        else if(a/i<1){
            break;
        }
    }
    return lop;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;z=0;
        cin>>a;
        while(op(a)!=1){
            a/=op(a);
            z++;
        }
        while(a>1){
            z+=(a-1);
            a=1;
        }
        cout<<z<<endl;
    }
}


#include <iostream>
#include <math.h>
#include <cmath>
#include <bits/stdc++.h>
#include<set>
using namespace std;
long long p1[100000+100];
long long p2[100000+100];
long long int op(long long int a){
    long long int p=0;
    int lop=1;
    for(int i=2;i<=sqrt(a);i++){
        if(a%i==0){
            lop=i;
        }
        else if(a/i<1){
            break;
        }
    }
    return lop;
}
int main()
{
    long long int t1,t2,a,b,c,z=0,java=0,b1=0,b2=0;
    cin>>t1;
    while(t1!=0){t1--;z=0;
        cin>>a;
        while(op(a)!=1){
            a/=op(a);
        }
        while(a>1){
            z+=(a-1);
            a=1;
        }
        cout<<z<<endl;
    }
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;
        while(n!= 1){
            if(isPrime(n)){
                n--;
                moves++;
            }

            if(n == 2){
                moves += 1;
                break;
            } else if(n % 2 == 0 && n != 2){
                moves += 2;
                break;
            } else if(n % 3 == 0 && n != 3){
                moves += 3;
                break;
            }

            for(int i =n/2;i >3;i--){
                while(n % i == 0 && i != n){
                    n /= i;
                    moves++;
                }
            }
        }

        cout  <<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    bool check = false;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;
            if(n == 1){
                moves = 0;
            }else if(n == 2){
                moves += 1;
            } else if(n == 3){
                moves += 2;
            }else if(n % 2 == 0){
                moves += 2;
            } else if(n % 2 != 0){
                moves += 3;
            }

        cout <<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    bool check = false;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;
        while(n!= 1){
            if(isPrime(n)){
                n--;
                moves++;
            }

            if(n == 2){
                moves += 1;
                break;
            } else if(n % 2 == 0 && n != 2){
                moves += 2;
                break;
            } else if(n % 3 == 0 && n != 3){
                moves += 3;
                break;
            }

            for(int i =n/2;i >3;i--){
                if(n % i == 0){
                    n /= i;
                    moves++;
                    break;
                }
            }
        }

        cout  <<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    bool check = false;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;
            if(n == 1){
                moves = 0;
            }else if(n == 2){
                moves += 1;
            } else if(n % 2 == 0){
                moves += 2;
            } else if(n % 2 != 0){
                moves += 3;
            }

        cout  <<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    bool check = false;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;
            if(n == 1){
                moves = 0;
            }else if(n == 2){
                moves += 1;
            } else if(n == 3){
                moves += 2;
            }else if(n % 2 == 0){
                moves += 2;
            } else if(n % 2 != 0){
                moves += 3;
            }

        cout  <<" moves :"<<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    bool check = false;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;
        while(n!= 1){
            if(isPrime(n)){
                n--;
                moves++;
            }

            if(n == 2){
                moves += 1;
                break;
            } else if(n % 2 == 0 && n != 2){
                moves += 2;
                break;
            } else if(n % 3 == 0 && n != 3){
                moves += 3;
                break;
            }

            for(int i =5;i <n/2;i+=2){
                if(n % i == 0){
                    n = i;
                    moves++;
                    break;
                }
            }
        }

        cout  <<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    cin >> t;
    while(t--){
        bool check = false;
        long int n, moves = 0;
        cin >> n;
        while(n != 1){
            if(isPrime(n)){
                n--;
                moves++;
                //cout << "we are in prime loop \n";
            }

            for(int i = n/2;i >= 2;i--){
               // cout << "we are in for loop \n";
                check = true;
                if(n % i == 0 && n != i){
                    while(n % i == 0 && n != i){
                        moves++;
                        n /= i;
                    }
                }
            }
        }

        cout << moves << "\n";
    }
}

bool isPrime(long int n){
    long int temp = sqrt(n);
    if(n == 2){
        return true;
    }

    if(n%2 == 0){
        return false;
    }

    for(int i =3;i < temp;i+=2){
        if(n%i == 0){
            return false;
        }
    }

    return true;
}


#include<iostream>
#include <cmath>
using namespace std;
bool isPrime(long int n);

int main(){
    int t;
    cin >> t;
    while(t--){
        long int n, moves = 0;
        cin >> n;

        //cout << "n is :" << n;
        if(isPrime(n)){
            //cout << "prime\n";
            n--;
            moves++;
        }

        if(n == 2){
            moves += 1;
        } else if(n % 2 == 0 && n != 2){
            moves += 2;
        } else if(n % 3 == 0 && n != 3){
            moves += 3;
        }

        cout  <<moves << "\n";
    }
}

bool isPrime(long int n)
{
    if (n == 1)
        return false;

    int temp = sqrt(n);
    for (int i = 2; i <= temp; i++)
        if (n % i == 0){
            return false;
        }

    return true;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        int res;
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n===2){
            cout<<"1"<<endl;
            continue;
        }
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        if(i==int(sqrt(n))){
            f=1;
            n=n-1;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        int res;
        if(f==1){
            cout<<i+1<<endl;
            continue;
        }
        cout<<i<<endl;
    }
}


#inlcude<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int i;
        for(i=2;i<int(pow(n,1/2));i++){
            if(n%i==0){
                break;
            }
        }
        int res;
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        if(n%2==0){
            cout<<"2"<<endl;
        }
        else{
            cout<<"3"<<endl;
        }
        // cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        if(n%2==0&&n==3){
            cout<<"2"<<endl;
        }
        else{
            cout<<"3"<<endl;
        }
        // cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        if(i==int(sqrt(n))&&(n%int(sqrt(n)))!=0){
            f=1;
            n=n-1;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        }
        int res;
        if(f==1){
            cout<<i+1<<endl;
            continue;
        }
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        long long i;
        for(i=2;i<int(pow(n,1/2));i++){
            if((n%i)==0){
                break;
            }
        }
        int res;
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int i;
        for(i=2;i<n/2;i++){
            if((n%i)==0){
                break;
            }
        }
        int res;
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        if(n%2==0||n==3){
            cout<<"2"<<endl;
        }
        else{
            cout<<"3"<<endl;
        }
        // cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        if(i==int(sqrt(n))){
            f=1;
            n=n-1;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        }
        int res;
        if(f==1){
            cout<<i+1<<endl;
            continue;
        }
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int i;
        for(i=2;i<int(pow(n,1/2));i++){
            if(n%i==0){
                break;
            }
        }
        int res;
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n==2){
            cout<<"1"<<endl;
            continue;
        }
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        if(i==int(sqrt(n))){
            f=1;
            n=n-1;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        int res;
        if(f==1){
            cout<<i+1<<endl;
            continue;
        }
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        int res;
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        long long n;
        int f=0;
        cin>>n;
        if(n==1){
            cout<<"0"<<endl;
            continue;
        }
        if(n===2){
            cout<<"1"<<endl;
            continue;
        }
        long long i;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        if(i==int(sqrt(n))){
            f=1;
            n=n-1;
        for(i=2;i<int(sqrt(n));i++){
            if(n%i==0){
                break;
            }
        }
        }
        int res;
        if(f==1){
            cout<<i+1<<endl;
            continue;
        }
        cout<<i<<endl;
    }
}


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

void solve(vector<int>&temp, int n){
        for(int i=2; i<=n; ++i){
                for(int j=i*i; j<=n; j += i){
                        if(temp[j]==0){
                                temp[j]=i;
                        }
                }
        }
}
int main(){
        int t;
        cin >> t;
        while(t--){
                int n;
                cin >> n;
                vector<int>dp(n+1);
                dp[1]=0;
                dp[2]=1;
                dp[3]=2;
                if(n>3){
                        vector<int>temp(n+1,0);
                        solve(temp,n);
                        for(int i=4; i<=n; ++i){
                               if(temp[i]){
                               dp[i] = 1 + dp[temp[i]];
                                }
                                else{
                               dp[i] = 1 + dp[i-1];
                                }
                        }
                }
               cout << dp[n] << endl;
        }
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int solve(int n){
        if(n==1 || n==0) return 0;
        else if(n==2) return 1;
        else if(n==3) return 2;
        else{
                int x = sqrt(n);
                for(int i=x; i>1; --i){
                        if(n%i==0){
                                return 1+solve(i);
                        }
                }
                return 1+solve(n-1);
        }

}
int main(){
        int t;
        cin >> t;
        while(t--){
                int n;
                cin >> n;
                cout << solve(n) << endl;
        }
}


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

void solve(vector<int>&temp){
        for(int i=2; i<=n; ++i){
                for(int j=i*i; j<=n; j += i){
                        if(temp[j]==0){
                                temp[j]=i;
                        }
                }
        }
}
int main(){
        int t;
        cin >> t;
        while(t--){
                int n;
                cin >> n;
                vector<int>dp(n+1);
                dp[1]=0;
                dp[2]=1;
                dp[3]=2;
                vector<int>temp(n+1,0);
               solve(temp);
               for(int i=4; i<=n; ++i){
                       if(temp[i]){
                               dp[i] = 1 + dp[temp[i]];
                       }
                       else{
                               dp[i] = 1 + dp[i-1];
                       }
               }
               cout << dp[n] << endl;
        }
}


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

void solve(vector<int>&temp, int n){
        for(int i=2; i<=n; ++i){
                for(int j=i*i; j<=n; j += i){
                        if(temp[j]==0){
                                temp[j]=i;
                        }
                }
        }
}
int main(){
        int t;
        cin >> t;
        while(t--){
                int n;
                cin >> n;
                vector<int>dp(n+1);
                dp[1]=0;
                dp[2]=1;
                dp[3]=2;
                vector<int>temp(n+1,0);
               solve(temp,n);
               for(int i=4; i<=n; ++i){
                       if(temp[i]){
                               dp[i] = 1 + dp[temp[i]];
                       }
                       else{
                               dp[i] = 1 + dp[i-1];
                       }
               }
               cout << dp[n] << endl;
        }
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int solve(int n){
        if(n==1 || n==0) return 0;
        else if(n==2) return 1;
        else if(n==3) return 2;
        else{
                int x = sqrt(n);
                for(int i=x; i>1; --i){
                        if(n%i==0){
                                return 1+solve(n/i);
                        }
                }
                return 1+solve(n-1);
        }

}
int main(){
        int t;
        cin >> t;
        while(t--){
                int n;
                cin >> n;
                cout << solve(n) << endl;
        }
}