def solve(n, x, l):
    i = 0
    j = 0
    ans = -1
    s = sum(l)
    temp = s
    for i in range(n):
        s = temp
        for j in range(n-1, i-1, -1):
            if s % x != 0 and ans < j - i +1 :
                ans = j - i +1
                break
            s -= l[j]
        temp -= l[i]
    return ans

t = int(input())
for we in range(t):
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    print(solve(n, x, l))


def solve(n, x, l):
    s = sum(l)
    if s % x != 0:
        return n
    i = 0
    j = 0
    ans = -1
    p = 0
    while i < n and l[i] % x == 0:
        i += 1
        p = 1
    j = 0
    while j < n and l[n - j - 1] % x == 0:
        j += 1
        p = 1
    if p == 0:
        return -1
    ans = n - i - j
    if ans == 0:
        return -1
    return max(ans, -1)

t = int(input())
for we in range(t):
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    print(solve(n, x, l))


def solve(n, x, l):
    s = sum(l)
    if s % x != 0:
        return n
    i = 0
    j = 0
    ans = -1
    p = 0
    q = 0
    s1 = 0
    while i < n and s1 % x == 0:
        if i == n-1:
            q = 1
        s1 += l[i]
        i += 1
    j = 0
    s2 = 0
    while j < n and s2 % x == 0:
        if j == n-1:
            p = 1
        s2 += l[n-j-1]
        j += 1
    if p == 1 or q == 1:
        return -1
    # print("------------", i, j)
    ans = max(n - i, n - j)
    return max(ans, -1)

t = int(input())
for we in range(t):
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    print(solve(n, x, l))


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    ct = 0
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x == 0:
                ct += 1
        if ct % 2 == 0:
            print(q - ct - 1)
        else:
            print(q - ct)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    ct = 0
    s = 0
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q//2):
            if a[i] % x != 0 and a[q - i - 1]:
                ct += 1
                break
        if ct == 0:
            print('-1')
        else:
            print(q-ct - 1)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x != 0:
                z = i
                boo = True
                break
            if a[q - i - 1] % x!=0:
                h = (q - i - 1)
                boo = True
                break

        if not boo:
            print('-1')
        else:
            print(q - min(z,h) - 1)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    ct = 0
    s = 0
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q//2):
            if a[i] % x != 0 and a[q - i - 1]:
                ct += 1
                break
        if ct == 0:
            print('-1')
        else:
            print(q-ct)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    ct = 0
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x == 0:
                ct += 1
        print(q - ct -1)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x != 0:
                j = i
                boo = True
                break

        if not boo:
            print('-1')
        else:
            print(q - j -1)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[q - i - 1] % x != 0:
                h = (q - i - 1)
                boo = True
                break

        if not boo:
            print('-1')
        else:
            print(h)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x != 0 or a[q - i - 1] % x!=0:
                print(q - i - 1)
                boo = True
                break

        if not boo:
            print('-1')

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x != 0:
                z = i
                boo = True
                break
        for i in range(q):
            if a[q - i - 1] % x != 0:
                h = (q - i - 1)
                boo = True
                break

        if not boo:
            print('-1')
        else:
            print(q - min(z,h) - 1)

    else:
        print(q)


for t in range(int(input())):
    n = list(map(int, input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int, input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x != 0:
                z = i
                boo = True
                break
        for j in range(q):
            if a[q - j - 1] % x != 0:
                h = (q - j - 1)
                boo = True
                break

        if not boo:
            print('-1')
        else:
            x = max(q - z - 1, h)
            print(x)

    else:
        print(q)


from itertools import combinations
a = []
co = 0
for o in range(int(input())):
    ni = list(map(int,input().split()))
    n = ni[0]
    x = ni[1]
    lst = list(map(int, input().split()))
    for k in range(2, n + 1):
        for i in list(combinations(lst, k)):
            if sum(i) % x != 0:
                a.append(len(i))
                co += 1

    if co == 0:
        print('-1')
    else:
        print(max(a))


t in range(int(input())):
    n = list(map(int,input().split()))
    q = n[0]
    x = n[1]
    boo = False
    a = list(map(int,input().split()))
    if sum(a) % x == 0:
        for i in range(q):
            if a[i] % x != 0 or a[q - i - 1] % x!=0:
                print(q - i - 1)
                boo = True
                break

        if not boo:
            print('-1')

    else:
        print(q)


t=int(input())
for i in range(0,t):
    n,x=map(int,input().split())
    o=list(map(int,input().split()))
    s=0
    b=0
    e=0
    m=0
    if(x==1):
        print(-1)
    else:
        for j in range(0,n):
            s=s+o[j]
            e=j+1
            while(s%x==0 and s>=0 and b<e):
                s=s-o[b]
                b=b+1
            if(e-b>m):
                m=e-b
        o.reverse()
        e=0
        b=0
        mm=0
        s=0
        for j in range(0,n):
            s=s+o[j]
            e=j+1
            while(s%x==0 and s>=0 and b<e):
                s=s-o[b]
                b=b+1
            if(e-b>mm):
                mm=e-b
        if(max(mm,m)>0):
            print(max(mm,m))
        else:
            print(-1)


t=int(input())
for i in range(0,t):
    n,x=map(int,input().split())
    o=list(map(int,input().split()))
    s=0
    b=0
    e=0
    if(x==1):
        print(-1)
    else:
        for j in range(0,n):
            s=s+o[j]
            e=j+1
            while(s%x==0 and s>=0 and b<e):
                s=s-o[b]
                b=b+1
        if(b!=e):
            print(e-b)
        else:
            print(-1)


t=int(input())
for i in range(0,t):
    n,x=map(int,input().split())
    o=list(map(int,input().split()))
    s=0
    b=0
    e=0
    m=0
    if(x==1):
        print(-1)
    else:
        s=sum(o)
        dd=s
        if(s%x==0):
            f=-1
            for j in range(0,n):
                s=s-o[j]
                dd=dd-o[n-j-1]
                if(s%x!=0 or dd%x!=0):
                    print(n-j-1)
                    f=0
                    break
            if(f==-1):
                print(-1)
        else:
            print(n)


t=int(input())
for i in range(0,t):
    n,x=map(int,input().split())
    o=list(map(int,input().split()))
    s=0
    b=0
    e=0
    m=0
    if(x==1):
        print(-1)
    else:
        for j in range(0,n):
            s=s+o[j]
            e=j+1
            while(s%x==0 and s>=0 and b<e):
                s=s-o[b]
                b=b+1
            if(e-b>m):
                m=e-b
        if(m!=0):
            print(m)
        else:
            print(-1)


import math

t = int(input())

for i in range (t):
    n,x = list(map(int,input().split()))
    data = list(map(int,input().split()))
    div = []
    l_found = -1
    r_found = -1
    sum_ren = 0
    for j in range (n):
        div.append(data[j]%x)
        sum_ren = sum_ren + (data[j]%x)

    if sum_ren % x != 0:
        print(n)

    else:
        for j in range (n):
            if div[j] != 0:
                l_found = j
                break
        for j in range (n-1,-1,-1):
            if div[j] != 0:
                r_found = j
                break
        if l_found == -1 and r_found == -1:
            print(-1)
        else:
            print(max(n-l_found-1,r_found-1))


import math

t = int(input())

for i in range (t):
    n,x = list(map(int,input().split()))
    data = list(map(int,input().split()))
    div = []
    l_found = -1
    r_found = -1
    sum_ren = 0
    for j in range (n):
        div.append(data[j]%x)
        sum_ren = sum_ren + (data[j]%x)

    if sum_ren % x != 0:
        print(n)

    else:
        for j in range (n):
            if div[j] != 0:
                l_found = j
                break
        for j in range (n-1,-1,-1):
            if div[j] != 0:
                r_found = j
                break
        if l_found == -1 and r_found == -1:
            print(-1)
        else:
            if l_found != -1 and r_found != -1:
                print(max(n-l_found-1,r_found-1))
            elif l_found == -1:
                print(r_found-1)
            else:
                print(n-l_found-1)


import math

t = int(input())

for i in range (t):
    n,x = list(map(int,input().split()))
    max_combo = 0
    combo = 0
    total =0
    data = list(map(int,input().split()))
    for j in range (n):
        total = total + data[j]
        if total % x != 0:
            combo = combo + 1
        elif total % x == 0:
            if combo > max_combo:
                max_combo = combo
            if data[j] % x != 0:
                total = data[j]
                combo = 1
            else:
                total = 0
                combo = 0
    if combo > max_combo:
        max_combo = combo

    if max_combo == 0:
        print(-1)
    else:
        print(max_combo)


import math

t = int(input())

for i in range (t):
    n,x = list(map(int,input().split()))
    data = list(map(int,input().split()))
    div = []
    l_found = -1
    r_found = -1
    sum_ren = 0
    for j in range (n):
        div.append(data[j]%x)
        sum_ren = sum_ren + (data[j]%x)

    if sum_ren % x != 0:
        print(n)

    else:
        for j in range (n):
            if div[j] != 0:
                l_found = j
                break
        for j in range (n-1,-1,-1):
            if div[j] != 0:
                r_found = j
                break
        if l_found == -1 and r_found == -1:
            print(-1)
        else:
            print(max(n-l_found-1,r_found))


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n, x = mints()
	a = list(mints())
	i = 0
	while i < n and a[i] % x == 0:
		i += 1
	j = n
	while j > 0 and a[j-1] % x == 0:
		j -= 1
	if j - i > 0:
		s = sum(a[i:j])
		if s % x != 0:
			print(j - i)
		elif j - i - 1 > 0:
			print(j - i - 1)
		else:
			print(-1)
	else:
		print(-1)

for i in range(mint()):
	solve()


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n, x = mints()
	a = list(mints())
	i = 0
	while i < n and a[i] % x == 0:
		i += 1
	j = n
	while j > 0 and a[j-1] % x == 0:
		j -= 1
	if j - i > 0:
		s = sum(a[i:j])
		if s % x == 0:
			print(j-i)
		elif j - i > 0:
			print(j - i)
		else:
			print(-1)
	else:
		print(-1)

for i in range(mint()):
	solve()


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n, x = mints()
	a = list(mints())
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		i = 0
		while i < n and a[i] % x == 0:
			i += 1
		j = n
		while j > 0 and a[j-1] % x == 0:
			j -= 1
		print(i, j)
		if j - i <= 0:
			print(-1)
		else:
			print(max(j - 1, n - i - 1))

for i in range(mint()):
	solve()


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n, x = mints()
	a = list(mints())
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		i = 0
		while i < n and a[i] % x == 0:
			i += 1
		j = n
		while j > 0 and a[j-1] % x == 0:
			j -= 1
		if j - i <= 0:
			print(-1)
		else:
			print(max(j - 1, n - i - 1))

for i in range(mint()):
	solve()


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n, x = mints()
	a = list(mints())
	i = 0
	while i < n and a[i] % x == 0:
		i += 1
	j = n
	while j > 0 and a[j-1] % x == 0:
		j -= 1
	print(j-i if j-i > 0 else -1)

for i in range(mint()):
	solve()


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n, x = mints()
	a = list(mints())
	i = 0
	while i < n and a[i] % x == 0:
		i += 1
	j = n
	while j > 0 and a[j-1] % x == 0:
		j -= 1
	if j - i > 0:
		s = sum(a[i:j])
		if s % x == 0:
			print(j - i)
		elif j - i - 1 > 0:
			print(j - i - 1)
		else:
			print(-1)
	else:
		print(-1)

for i in range(mint()):
	solve()


for _ in range(int(input())):
   n, x = map(int, input().split())
   a = list(map(int, input().split()))
   A = a
   l = []
   lon, tmp, ans = sum(A), 0, 0
   for i in range(n):
      if A[i]%x==0:
         l.append(0)
      else:
         l.append(1)
   rl = l[::-1]
   if 1 not in l: print(-1)
   elif lon%x!=0: print(n)
   else:
      for i in range(n):
         if l[i]==1 or rl[i]==1:
            print(len(l[i+1:]))
            break


for _ in range(int(input())):
   n, x = map(int, input().split())
   a = list(map(int, input().split()))
   A = a
   l = []
   lon, tmp, ans = sum(A), 0, 0
   for i in range(n):
      if A[i]%x==0:
         l.append(0)
      else:
         l.append(1)
   rl = l[::-1]
   if 1 not in l: print(-1)
   elif 0 not in l: print(n)
   else:
      for i in range(n):
         if l[i]==1 or rl[i]==1:
            print(len(l[i+1:]))
            break


for _ in range(int(input())):
   n, x = map(int, input().split())
   a = list(map(int, input().split()))
   A = a
   l = []
   lon, tmp, ans = sum(A), 0, 0
   for i in range(n):
      if A[i]%x==0:
         l.append(0)
      else:
         l.append(1)
   rl = l[::-1]
   if 1 not in l: print(-1)
   elif 0 not in l or lon%x!=0: print(n)
   else:
      for i in range(n):
         if l[i]==1 or rl[i]==1:
            print(len(l[i+1:]))
            break


for _ in range(int(input())):
   n, x = map(int, input().split())
   a = list(map(int, input().split()))
   A = a
   l = []
   lon, tmp, ans = sum(A), 0, 0
   for i in range(n):
      if A[i]%x==0:
         l.append(0)
      else:
         l.append(1)
   rl = l[::-1]
   if 1 not in l: print(-1)
   elif 0 not in l and lon%x!=0: print(n)
   else:
      for i in range(n):
         if l[i]==1 or rl[i]==1:
            print(len(l[i+1:]))
            break


for i in range(int(input())):
    a=list(map(int,input().strip().split()))[:2]
    b=list(map(int,input().strip().split()))[:a[0]]
    b.sort()
    sum=0
    for j in b:
        if j==0:
            b.remove(j)
        else:
            sum+=j
    k=0
    if sum%a[1]!=0:
        print(a[0])
    else:
        b.reverse()
        c=0
        for k in b:
            if k%a[0]!=0 and a[0]%k!=0:
                c=k
        if c==0:
            print(-1)
        else:
            print(len(b)-1)


for i in range(int(input())):
    a=list(map(int,input().strip().split()))[:2]
    b=list(map(int,input().strip().split()))[:a[0]]
    b.sort()
    sum=0
    for j in b:
        sum+=j
    k=0
    while sum%a[1]==0:
        if len(b)==0:
            break
        else:
            sum=sum-b[k]
            b.remove(b[k])
    if len(b)==0:
        print(-1)
    else:
        print(len(b))


for i in range(int(input())):
    a=list(map(int,input().strip().split()))[:2]
    b=list(map(int,input().strip().split()))[:a[0]]
    b.sort()
    sum=0
    for j in b:
        if j==0:
            b.remove(j)
        else:
            sum+=j
    k=0
    if sum%a[1]!=0:
        print(a[0])
    else:
        while b[0]%a[1]==0:
            b.remove(b[0])
            if len(b)==0:
                break
        if len(b)==0:
            print(-1)
        else:
            print(len(b)-1)


for i in range(int(input())):
    a=list(map(int,input().strip().split()))[:2]
    b=list(map(int,input().strip().split()))[:a[0]]
    sum=0
    for j in b:
            sum+=j
    sum1=sum
    if sum%a[1]!=0:
        print(a[0])
    else:
        for k in range(len(b)):
            sum-=b[k]
            if sum%a[1]!=0:
                break
        b.reverse()
        for l in range(len(b)):
            sum1-=b[l]
            if sum1%a[1]!=0:
                break
        t=0
        if l>k:
            t=len(b)-k-1
        else:
            t=len(b)-l-1
        if t==0:
            print(-1)
        else:
            print(t)


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
string n;
bool bol;
int main(){
    cin>>n;
    char sw;
    int b;
    for(int i=n.size()-1;i>=0;i--){
        if(n[i]%2!=0){
            bol=true;
            b=i;
            break;
        }
    }
    if(bol==true){
        bol=false;
        for(int i=0;i<n.size();i++){
            if(n[i]%2==0){
                sw=n[i];
                n[i]=n[b];
                n[b]=sw;
                bol=true;
                break;
            }
        }
        if(bol==true){
            cout<<n<<endl;
            return 0;
        }
        else{
            printf("-1\n");
            return 0;
        }
    }
    else{
        printf("-1\n");
    }
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
string n;
bool bol;
int main(){
    cin>>n;
    char sw;
    for(int i=0;i<n.size();i++){
        if(n[i]%2==0){
            sw=n[i];
            n[i]=n[n.size()-1];
            n[n.size()-1]=sw;
            cout<<n<<endl;
            return 0;
        }
    }
    printf("-1\n");
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
string n;
bool bol;
int main(){
    cin>>n;
    char sw;
        for(int i=0;i<n.size();i++){
            if(n[i]%2==0){
                if(n[i]<n[n.size()-1]){
                sw=n[i];
                n[i]=n[n.size()-1];
                n[n.size()-1]=sw;
                cout<<n<<endl;
                return 0;
                }
                else bol=true;
            }
        }
        if(bol==true){
            for(int i=n.size()-2;i>=0;i--){
                if(n[i]%2==0){
                        sw=n[i];
                        n[i]=n[n.size()-1];
                        n[n.size()-1]=sw;
                        cout<<n<<endl;
                        return 0;
                }
            }
        }
        printf("-1\n");
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
string n;
bool bol;
int main(){
    cin>>n;
    char sw;
    for(int i=n.size()-2;i>=0;i--){
        if(n[i]%2==0){
            if(n[i]>n[n.size()-1]){
            sw=n[i];
            n[i]=n[n.size()-1];
            n[n.size()-1]=sw;
            cout<<n<<endl;
            return 0;}
            else{
                bol=true;
            }
        }
    }
    if(bol==true){
        for(int i=0;i<n.size();i++){
            if(n[i]%2==0){
                sw=n[i];
            n[i]=n[n.size()-1];
            n[n.size()-1]=sw;
            cout<<n<<endl;
            return 0;
            }
        }
    }
    printf("-1\n");

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>

// Suppress some compilation warning messages
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1

using namespace std;

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
#define INF 1000000000

int main()
{
    string str,tmp;
    getline(cin, str);
    int index1 = -1; for (int i = 0; i < str.length(); i++) if (((int)(str[i] - '0')) % 2 == 0) { index1 = i; break; }
    int index = str.length();

    string maxx = "";
    for (int i = 0; i < index; i++)
    {
        if (i==index1||((int)(str[i]-'0')%2==0)&&str[i]<str[index-1]){
            swap(str[i], str[index - 1]);
            if (str>maxx) maxx = str;
            swap(str[i], str[index - 1]);
        }
        else if ((int)(str[i] - '0') % 2 == 0) index1 = i;
    }
    if (maxx.length() == 0){cout << -1; return 0;}
    swap(str[index1], str[index - 1]);
    if (str>maxx) maxx = str;
    swap(str[index1], str[index - 1]);

    cout << maxx;
}


/*
بسم الله الرحمن الرحيم
*/

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(V)        ((int)((v).size()))
#define pp(x)               push_back(x)
#define mk(x,y)           make_pair(x,y)
#define ck(a)               (a<1 || a>9)
#define lop(i,n)     for(ll i=0;i<n;i++)
#define loop(i,f,l)  for(ll i=f;i<l;i++)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define scl(n)          scanf("%lld",&n)
#define sc(n)             scanf("%d",&n)
#define INF                   1000000000
#define PI             3.141592653589793

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef pair<char, int>  chi;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
typedef vector<ll>       vll;
typedef vector<vi>       vvl;

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return ll(1); }
//READ("input.txt");WRITE("output.txt");
//#include <bits/stdc++.h>
//using namespace std;

ss s,t,m;
int main() {
    cin >> s;
    t = s;
    m = "";
    loop(i, 0, s.size())
    {
        if ((s[i] - '0') % 2 == 0)
        {
            swap(s[i], s[s.size() - 1]);
            t = s;
            swap(s[i], s[s.size() - 1]);
            if (!m.size()) m = t;
            else m = max(m, t);
        }
    }
    if (t != s) cout << m;
    else cout << -1;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>

// Suppress some compilation warning messages
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1

using namespace std;

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
#define INF 1000000000

bool iseven(string s)
{
    int n = (int)(s[s.length() - 1] - '0');
    if (n % 2 == 0) return true;
    else return false;
}

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

    string max = "";
    for (int i = 0; i < str.length(); i++)
    {
        for (int j = 0; j < str.length(); j++)
        {
            swap(str[i], str[j]);
            if (iseven(str) && str>max)
                max = str;
            swap(str[i], str[j]);
        }
    }
    if (max.length()!=0) cout<<max;
    else printf("%d",-1);
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>

// Suppress some compilation warning messages
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1

using namespace std;

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
#define INF 1000000000

bool iseven(char s)
{
    int n = (int)(s - '0');
    if (n % 2 == 0) return true;
    else return false;
}

int main()
{
    string str;
    getline(cin, str);
    int index = str.length();

    string maxx = "";
    for (int i = 0; i < index; i++)
    {
        if (iseven(str[i])){
            swap(str[i], str[index - 1]);
            maxx = max(maxx, str);
            swap(str[i], str[index - 1]);
        }
    }
    if (maxx.length() != 0) cout << maxx;
    else printf("%d", -1);
}


/*
بسم الله الرحمن الرحيم
*/

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(V)        ((int)((v).size()))
#define pp(x)               push_back(x)
#define mk(x,y)			  make_pair(x,y)
#define ck(a)               (a<1 || a>9)
#define lop(i,n)     for(ll i=0;i<n;i++)
#define loop(i,f,l)  for(ll i=f;i<l;i++)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define scl(n)          scanf("%lld",&n)
#define sc(n)             scanf("%d",&n)
#define INF                   1000000000
#define PI             3.141592653589793

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef pair<char, int>  chi;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
typedef vector<ll>       vll;
typedef vector<vi>		 vvl;

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return ll(1); }
//READ("input.txt");WRITE("output.txt");
//#include <bits/stdc++.h>
//using namespace std;

ss s,t,m;
int main() {
	cin >> s;
	loop(i, 0, s.size())
		if ((s[i] - '0') % 2 == 0 && s[i] < s[s.size() - 1]){ swap(s[i], s[s.size() - 1]); cout << s; return 0; }
	for (int i = s.size() - 1; i >= 0; i--)
		if ((s[i] - '0') % 2 == 0){ swap(s[i], s[s.size() - 1]); cout << s; return 0; }
	cout << -1;
}


/*
بسم الله الرحمن الرحيم
*/

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(V)        ((int)((v).size()))
#define pp(x)               push_back(x)
#define mk(x,y)           make_pair(x,y)
#define ck(a)               (a<1 || a>9)
#define lop(i,n)     for(ll i=0;i<n;i++)
#define loop(i,f,l)  for(ll i=f;i<l;i++)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define scl(n)          scanf("%lld",&n)
#define sc(n)             scanf("%d",&n)
#define INF                   1000000000
#define PI             3.141592653589793

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef pair<char, int>  chi;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
typedef vector<ll>       vll;
typedef vector<vi>       vvl;

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return ll(1); }
//READ("input.txt");WRITE("output.txt");
//#include <bits/stdc++.h>
//using namespace std;

ss s,t,m;
int main() {
    cin >> s;
    t = s;
    m = "";
    int dp[10] = { 0 };
    loop(i, 0, s.size())
    {
        if ((s[i] - '0') % 2 == 0&&!dp[s[i]-'0'])
        {
            dp[s[i] - '0'] = 1;
            swap(s[i], s[s.size() - 1]);
            t = s;
            swap(s[i], s[s.size() - 1]);
            if (!m.size()) m = t;
            else m = max(m, t);
        }
    }
    if (t != s) cout << m;
    else cout << -1;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>

// Suppress some compilation warning messages
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1

using namespace std;

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
#define INF 1000000000

bool iseven(char s)
{
    int n = (int)(s - '0');
    if (n % 2 == 0) return true;
    else return false;
}

int main()
{
    string str;
    cin >> str;
    int index = str.length();

    string max = "";
    for (int i = 0; i < index; i++)
    {
        if (iseven(str[i])){
            swap(str[i], str[index - 1]);
            if (str>max)
                max = str;
            swap(str[i], str[index - 1]);
        }
    }
    if (max.length() != 0) cout << max;
    else cout << -1;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>

// Suppress some compilation warning messages
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1

using namespace std;

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
#define INF 1000000000

bool iseven(string s)
{
    int n = (int)(s[s.length() - 1] - '0');
    if (n % 2 == 0) return true;
    else return false;
}

int main()
{
    string str;
    cin >> str;
    int index = str.length();

    string max = "";
    for (int i = 0; i < index; i++)
    {
        swap(str[i], str[index-1]);
        if (str>max&&iseven(str))
            max = str;
        swap(str[i],str[index-1]);
    }
    if (max.length()!=0) cout << max;
    else cout << -1;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstdlib>
#include <map>
#include <bitset>
#include <set>

using namespace std;

#define INF 1E+9
#define INFll 9223372036854775807
#define EPS 1E-7
#define MAXN
#define MAXL
#define MOD (10000007)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(a) (a).begin(), (a).end()
#ifdef DEBUG
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif

typedef long long LL ;
typedef long double dbl ;

int main(){

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

    string s;
    cin >> s;

    int mxD = -1, mxD1 = 1;

    for (int i = 0; i < s.length(); ++i)
        if ((s[i] - '0') % 2 == 0)
            if (mxD == -1 || s[mxD] > s[i])
                mxD = i;

    if (mxD == -1)
        cout << -1;
    else {
        swap(s[s.length() - 1], s[mxD]);
        cout << s;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstdlib>
#include <map>
#include <bitset>
#include <set>

using namespace std;

#define INF 1E+9
#define INFll 9223372036854775807
#define EPS 1E-7
#define MAXN
#define MAXL
#define MOD (10000007)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(a) (a).begin(), (a).end()
#ifdef DEBUG
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif

typedef long long LL ;
typedef long double dbl ;

int main(){

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

    string s;
    cin >> s;

    vector <string> ans;

    for (int i = 0; i < s.length(); ++i)
        if ((s[i] - '0') % 2 == 0) {
            swap(s[s.length() - 1], s[i]);

            ans.push_back(s);

            swap(s[s.length() - 1], s[i]);
        }

    if (ans.size() == 0) {
        cout << -1;
        return 0;
    }

    sort(all(ans));

    cout << ans.back();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstdlib>
#include <map>
#include <bitset>
#include <set>

using namespace std;

#define INF 1E+9
#define INFll 9223372036854775807
#define EPS 1E-7
#define MAXN
#define MAXL
#define MOD (10000007)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(a) (a).begin(), (a).end()
#ifdef DEBUG
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif

typedef long long LL ;
typedef long double dbl ;

int main(){

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

    string s;
    cin >> s;

    string ans = "000";

    int lastUp = -1;

    for (int i = 0; i < s.length(); ++i)
        if ((s[i] - '0') % 2 == 0) {
            if (lastUp == -1) {
                swap(s[i], s[s.length() - 1]);
                ans = s;
                swap(s[i], s[s.length() - 1]);
                lastUp = i;
            }
            else {
                int tmp1 = (s[s.length() - 1] - '0') * 10000 + (s[i] - '0') * 100 + (s[lastUp] - '0'),
                    tmp2 = (s[lastUp] - '0') * 10000 + (s[s.length() - 1] -'0') * 100 + (s[i] - '0');

                LOG(tmp1);
                LOG(tmp2);
                if (tmp2 > tmp1) {
                    swap(s[i], s[s.length() - 1]);
                    ans = s;
                    swap(s[i], s[s.length() - 1]);
                    lastUp = i;
                }

            }
        }

    if (ans == "000") {
        cout << -1;
        return 0;
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstdlib>
#include <map>
#include <bitset>
#include <set>

using namespace std;

#define INF 1E+9
#define INFll 9223372036854775807
#define EPS 1E-7
#define MAXN
#define MAXL
#define MOD (10000007)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(a) (a).begin(), (a).end()
#ifdef DEBUG
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif

typedef long long LL ;
typedef long double dbl ;

int main(){

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

    string s;
    cin >> s;

    string ans = "000";

    int lastUp = -1;

    for (int i = 0; i < s.length(); ++i)
        if ((s[i] - '0') % 2 == 0) {
            if (lastUp == -1) {
                swap(s[i], s[s.length() - 1]);
                ans = s;
                swap(s[i], s[s.length() - 1]);
                lastUp = i;
            }
            else {
                int tmp1 = s[s.length()] * 10000 + s[i] * 100 + s[lastUp],
                    tmp2 = s[lastUp] * 10000 + s[s.length()] * 100 + s[i];

                if (tmp2 < tmp1) {
                    swap(s[i], s[s.length() - 1]);
                    ans = s;
                    swap(s[i], s[s.length() - 1]);
                    lastUp = i;
                }

            }
        }

    if (ans == "000") {
        cout << -1;
        return 0;
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstdlib>
#include <map>
#include <bitset>
#include <set>

using namespace std;

#define INF 1E+9
#define INFll 9223372036854775807
#define EPS 1E-7
#define MAXN
#define MAXL
#define MOD (10000007)
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define all(a) (a).begin(), (a).end()
#ifdef DEBUG
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif

typedef long long LL ;
typedef long double dbl ;

int main(){

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

    string s;
    cin >> s;

    string ans = "000";

    int lastUp = -1;

    for (int i = 0; i < s.length(); ++i)
        if ((s[i] - '0') % 2 == 0) {
            if (lastUp == -1) {
                swap(s[i], s[s.length() - 1]);
                ans = s;
                swap(s[i], s[s.length() - 1]);
            }
            else {
                int tmp1 = s[s.length()] * 10000 + s[i] * 100 + s[lastUp],
                        tmp2 = s[lastUp] * 10000 + s[s.length()] * 100 + s[i];

                if (tmp2 > tmp1) {
                    swap(s[i], s[s.length() - 1]);
                    ans = s;
                    swap(s[i], s[s.length() - 1]);
                    lastUp = i;
                }

            }
        }

    if (ans == "000") {
        cout << -1;
        return 0;
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	int l = (str[str.length() - 1] - '0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = (str[i] - '0');
		if (val % 2 == 0 && m == -1 && val < l)	m = i;
		if (val % 2 == 0 && m == -1 && val > l) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.length() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.length() - 1], str[m]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 1; i <= str.size(); i++)
		{
			if ((str[str.size() - 1 - i] -'0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size()], str[str.size() - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

long long toInt(string str){
	istringstream buffer(str);
	long long val;
	buffer >> val;
	return val;
}

int main()
{
	string n;
	cin >> n;
	int se = -1 , be = -1;
	int ld = ((int) n.at(n.length() - 1)) - ((int) '0');
	for(int i = 0 ; i < n.length() ; i++){
		int val = ((int) n.at(i)) - ((int) '0');
		if(val % 2 == 0 && se == -1 && val < ld ){
			se = i;
		}
		if(val % 2 == 0 && se == -1 && val > ld){
			be = i;
		}
	}
	if(se == -1 && be == -1){
		cout << -1 << endl;
	}else if(se != -1){
		swap(n[se],n[n.length() - 1]);
		cout <<  n << endl;;
	}else if(be != -1){
		swap(n[be],n[n.length() - 1]);
		cout << n << endl;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if ((str[str.size() - 1] - '0') % 2 == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0)
			{
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] - '0') % 2 == 0 && str[str.size() - 1] < str[str.size() - 2 - i])
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 2 - i]);
				break;
			}
			if (i == str.size() - 1)
			{
				tr = false;
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int tr = 0;
	int m = -1,s = -1;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = -1;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') < (str[str.size() - 1] - '0'))	m = i;
			if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') > (str[str.size() - 1] - '0')) s = i;
		}
	}
	if (tr == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.size() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.size() - 1], str[m]);
		cout << str;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	for (int i = 0; i < str.size(); i++)
	{
		if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') < (str[str.size() - 1] - '0'))	m = i;
		if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') > (str[str.size() - 1] - '0')) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.size() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.size() - 1], str[m]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

long long toInt(string str){
	istringstream buffer(str);
	long long val;
	buffer >> val;
	return val;
}

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	int l = ((int)str[str.length() - 1] - (int)'0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = ((int)str[i] - (int)'0');
		if (val % 2 == 0 && m == -1 && val < l)	m = i;
		if (val % 2 == 0 && m == -1 && val > l) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.length() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.length() - 1], str[m]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 1; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] - '0') % 2 == 0 && str[str.size() - 1] < str[str.size() - 1 - i])
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 1 - i]);
				break;
			}
			if (i == str.size() - 1)
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 1 - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] - '0') % 2 == 0 && str[str.size() - 1] < str[str.size() - 2 - i])
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 2 - i]);
				break;
			}
			if (i+1 == str.size() - 1)
			{
				tr = false;
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if (((str[str.size() - 1] - '0') % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0)
			{
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
		tr = true;
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

long long toInt(string str){
	istringstream buffer(str);
	long long val;
	buffer >> val;
	return val;
}

int main()
{
	string str; cin >> str;
	int se = -1, be = -1;
	int ld = ((int)str.at(str.length() - 1)) - ((int) '0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = ((int)str[i] - (int)'0');
		if (val % 2 == 0 && se == -1 && val < ld) se = i;
		if (val % 2 == 0 && se == -1 && val > ld) be = i;
	}
	if (se == -1 && be == -1) cout << -1;
	else if (se != -1) {
		swap(str[str.length() - 1], str[se]);
		cout << str;
	}
	else if (be != -1)
	{
		swap(str[str.length() - 1], str[be]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 1; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] -'0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 1 - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = true;
	if ((str[str.size() - 1] - '0' % 2) == 0) continue;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int tr = 1;
	int max;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = -1;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') < (str[str.size() - 1] - '0'))
			{
				tr = 0;
				break;
			}
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') > (str[str.size() - 1] - '0')) max = i;
		}
	}
	if (tr == -1) cout << -1;
	else if (tr == 0) swap(str[str.size() - 1], str[0]);
	else if (tr == 1) swap(str[str.size() - 1], str[max]);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if (str[str.size() - 1] - '0' % 2 == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] - '0' == 0)
			{
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	string str; cin >> str;
	int se = -1, be = -1;
	int ld = ((int)str.at(str.length() - 1)) - ((int) '0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = ((int)str[i] - (int)'0');
		if (val % 2 == 0 && se == -1 && val < ld) se = i;
		if (val % 2 == 0 && se == -1 && val > ld) be = i;
	}
	if (se == -1 && be == -1) cout << -1;
	else if (se != -1) {
		swap(str[str.length() - 1], str[se]);
		cout << str;
	}
	else if (be != -1)
	{
		swap(str[str.length() - 1], str[be]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0)
			{
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
		tr = true;
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <string>
#include <iostream>

int main()
{
    string s;
    int i, len;
    int index, temp, odd;
    int flag=0;
    cin >> s;
    len = s.length();
    odd = s[len-1]-'0';
    for(i=len-1; i>=0; i--)
    {
        temp = s[i]-'0';
        if(temp%2==0)
        {
            flag++;
            if(flag==1)
            {
                index = i;
            }
            if(odd>temp)
            {
                index = i;
            }
        }
    }
    if(flag==0)
        cout <<"-1" << endl;
    else
    {
        swap(s[index], s[len-1]);
        cout << s << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int a[100] = { 0 };
	bool tr = false;
	for (int i = 0; i < 100; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < 100; i++)
	{
		if (a[i] % 2 == 0)
		{
			tr = true;
			swap(a[i], a[99]);
			break;
		}
	}
	if(tr) for (int i = 0; i < 100; i++) cout << a[i];
	else cout << "-1";
	return 0;
}


#include <iostream>
#include <string>

using namespace std;
int main()
{
    string s;
    int i, len;
    int index, temp, odd;
    int flag=0;
    cin >> s;
    len = s.length();
    odd = s[len-1]-'0';
    for(i=len-1; i>=0; i--)
    {
        temp = s[i]-'0';
        if(temp%2==0)
        {
            flag++;
            if(flag==1)
            {
                index = i;
            }
            if(odd>temp)
            {
                index = i;
            }
        }
    }
    if(flag==0)
        cout <<"-1" << endl;
    else
    {
        swap(s[index], s[len-1]);
        cout << s << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	for (int i = 0; i < str.length(); i++)
	{
		if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') < (str[str.length() - 1] - '0'))	m = i;
		if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') > (str[str.length() - 1] - '0')) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.length() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.length() - 1], str[m]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 1; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] - '0') % 2 == 0 && str[str.size() - 1] < str[str.size() - 1 - i])
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 1 - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int tr = 1;
	int max;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = -1;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') < (str[str.size() - 1] - '0'))
			{
				max = i;
				tr = 1;
			}
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') > (str[str.size() - 1] - '0')) max = i;
		}
	}
	if (tr == -1) cout << -1;
	else if (tr == 1) {
		swap(str[str.size() - 1], str[max]);
		cout << str;
	}
	else if (tr == 0)
	{
		swap(str[str.size() - 1], str[max]);
		cout << str;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0)
			{
				swap(str[str.size() - 1], str[i]);
				break;
			}
			tr = true;
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if (str[str.size() - 1] - '0' % 2 == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] - '0' == 0)
			{
				swap(str[str.size()], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if ((int)str[str.size() - 1] % 2 == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((int)str[i] % 2 == 0)
			{
				swap(str[str.size()], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int tr = 1;
	int max;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = -1;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') < (str[str.size() - 1] - '0'))
			{
				tr = 1;
				break;
			}
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') > (str[str.size() - 1] - '0')) max = i;
		}
	}
	if (tr == -1) cout << -1;
	else if (tr == 1) {
		swap(str[str.size() - 1], str[0]);
		cout << str;
	}
	else if (tr == 0)
	{
		swap(str[str.size() - 1], str[max]);
		cout << str;
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	int l = ((int)str[str.length() - 1] - (int)'0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = ((int)str[i] - (int)'0');
		if (val % 2 == 0 && m == -1 && val < l)	m = i;
		if (val % 2 == 0 && m == -1 && val > l) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.length() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.length() - 1], str[m]);
		cout << str;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr = false;
	if (str[str.size() - 1] - '0' % 2 == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] - '0' % 2 == 0)
			{
				swap(str[str.size() - 1], str[i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] -'0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 1 - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 1; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] - '0') % 2 == 0 && str[str.size() - 1] < str[str.size() - 1 - i])
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 1 - i]);
				break;
			}
			if (i == str.size() - 1)
			{
				tr = false;
				swap(str[str.size() - 1], str[0]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int tr = 1;
	int max;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = -1;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') < (str[str.size() - 1] - '0'))
			{
				tr = 1;
				break;
			}
			if ((str[i] - '0') % 2 == 0 && tr == 0 && (str[i] - '0') > (str[str.size() - 1] - '0')) max = i;
		}
	}
	if (tr == -1) cout << -1;
	else if (tr == 1) swap(str[str.size() - 1], str[0]);
	else if (tr == 0) swap(str[str.size() - 1], str[max]);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[str.size() - 1 - i] - '0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size() - 1], str[str.size() - 2 - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

long long toInt(string str){
	istringstream buffer(str);
	long long val;
	buffer >> val;
	return val;
}

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	int l = ((int)str[str.length() - 1] - (int)'0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = ((int)str[i] - (int)'0');
		if (val % 2 == 0 && m == -1 && val < l)	m = i;
		if (val % 2 == 0 && m == -1 && val > l) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.length() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.length() - 1], str[m]);
		cout << str;
	}
	return 0;
}


int main()
{
    string s;
    int i, len;
    int index, temp, odd;
    int flag=0;
    cin >> s;
    len = s.length();
    odd = s[len-1]-'0';
    for(i=len-1; i>=0; i--)
    {
        temp = s[i]-'0';
        if(temp%2==0)
        {
            flag++;
            if(flag==1)
            {
                index = i;
            }
            if(odd>temp)
            {
                index = i;
            }
        }
    }
    if(flag==0)
        cout <<"-1" << endl;
    else
    {
        swap(s[index], s[len-1]);
        cout << s << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	int tr = 0;
	int m = -1,s = -1;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = -1;
	else
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') < (str[str.size() - 1] - '0'))	m = i;
			if ((str[i] - '0') % 2 == 0 && m == -1 && (str[i] - '0') > (str[str.size() - 1] - '0')) s = i;
		}
	}
	if (tr == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.size() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.size() - 1], str[m]);
		cout << str;
	}
	else cout << str;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str; cin >> str;
	bool tr;
	if ((str[str.size() - 1] - '0' % 2) == 0) tr = true;
	else
	{
		for (int i = 1; i <= str.size(); i++)
		{
			if ((str[str.size() - i] -'0') % 2 == 0)
			{
				tr = false;
				swap(str[str.size()], str[str.size() - i]);
				break;
			}
		}
	}
	cout << (tr ? "-1" : str);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

long long toInt(string str){
	istringstream buffer(str);
	long long val;
	buffer >> val;
	return val;
}

int main()
{
	string str; cin >> str;
	int m = -1, s = -1;
	int ld = ((int)str.at(str.length() - 1)) - ((int) '0');
	for (int i = 0; i < str.length(); i++)
	{
		int val = ((int)str[i] - (int)'0');
		if (val % 2 == 0 && m == -1 && val < ld) m = i;
		if (val % 2 == 0 && m == -1 && val > ld) s = i;
	}
	if (s == -1 && m == -1) cout << -1;
	else if (s != -1) {
		swap(str[str.length() - 1], str[s]);
		cout << str;
	}
	else if (m != -1)
	{
		swap(str[str.length() - 1], str[m]);
		cout << str;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define forn(i,n) for (int i = int(0); i < int(n); i++)
#define forb(i,n) for (int i = int(n-1); i >= int(0); i--)
#define for1(i,n) for (int i = int(1); i <= int(n); i++)
#define fore(i,a,n) for (int i = int(a); i < int(n); i++)

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define dist(x1, y1, x2, y2) sqrt(ld (sqr(x1 - x2) + sqr(y1 - y2)))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 2001;
const int MAXN = 30001;
const int logn = 12;
const int inf = (int) 1e9;
const int alpha = 26;
const int my_hash = 31;
const long long base = (ll) 1e9;
const long long my_mod = 2674894331;
const long long l_inf = (ll) 4e18;
const long long mod = (ll) 1e9 + 7;
const long long l_mod = (ll) 1e18 - 11;
const double fi = (sqrt(5.0) + 1) / 2.0;
const double pi = acos(-1.0);
const double eps = 1e-8;
const double EPS = 0.00005;

int main() {
    ios_base::sync_with_stdio(0);
    int m, t, r, sum = 0, ans = 0;
    scanf("%d %d %d ", &m, &t, &r);
    if (t < r) {
        printf("-1");
        exit(0);
    }
    vector<int> a(maxn), cnt(maxn);
    forn(i, m) {
        int x;
        scanf("%d ", &x);
        a[x] = 1;
    }
    forn(i, maxn) {
        if (a[i] == 1) {
            if (sum < r) {
                ans += r - sum;
                fore(j, i + t - (r - sum), i + t)
                    cnt[j]--;
                sum = r;
            }
        }
        sum += cnt[i];
    }
    printf("%d", ans);
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define forn(i,n) for (int i = int(0); i < int(n); i++)
#define forb(i,n) for (int i = int(n-1); i >= int(0); i--)
#define for1(i,n) for (int i = int(1); i <= int(n); i++)
#define fore(i,a,n) for (int i = int(a); i < int(n); i++)

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define dist(x1, y1, x2, y2) sqrt(ld (sqr(x1 - x2) + sqr(y1 - y2)))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 501;
const int MAXN = 30001;
const int logn = 12;
const int inf = (int) 1e9;
const int alpha = 26;
const int my_hash = 31;
const long long base = (ll) 1e9;
const long long my_mod = 2674894331;
const long long l_inf = (ll) 4e18;
const long long mod = (ll) 1e9 + 7;
const long long l_mod = (ll) 1e18 - 11;
const double fi = (sqrt(5.0) + 1) / 2.0;
const double pi = acos(-1.0);
const double eps = 1e-8;
const double EPS = 0.00005;

int main() {
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = int(s.sz);
	bool check = false;
	forn(i, n) {
		s[i] -= '0';
		if (s[i] % 2 == 0)
			check = true;
	}
	if (!check) {
		printf("-1");
		exit(0);
	}
	int mn = -1, mx = -1;
	forn(i, n - 1) {
		if (s[i] % 2 == 0 && (mn == -1 || s[i] < s[mn]))
			mn = i;
		if (s[i] % 2 == 0 && (mx == -1 || s[i] <= s[mx]))
			mx = i;
	}
	if (s[mn] > s[n - 1])
		swap(s[mx], s[n - 1]);
	else
		swap(s[mn], s[n - 1]);
	forn(i, n)
		s[i] += '0';
	cout << s;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define forn(i,n) for (int i = int(0); i < int(n); i++)
#define forb(i,n) for (int i = int(n-1); i >= int(0); i--)
#define for1(i,n) for (int i = int(1); i <= int(n); i++)
#define fore(i,a,n) for (int i = int(a); i < int(n); i++)

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define dist(x1, y1, x2, y2) sqrt(ld (sqr(x1 - x2) + sqr(y1 - y2)))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 501;
const int MAXN = 30001;
const int logn = 12;
const int inf = (int) 1e9;
const int alpha = 26;
const int my_hash = 31;
const long long base = (ll) 1e9;
const long long my_mod = 2674894331;
const long long l_inf = (ll) 4e18;
const long long mod = (ll) 1e9 + 7;
const long long l_mod = (ll) 1e18 - 11;
const double fi = (sqrt(5.0) + 1) / 2.0;
const double pi = acos(-1.0);
const double eps = 1e-8;
const double EPS = 0.00005;

int main() {
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = int(s.sz);
	bool check = false;
	forn(i, n) {
		s[i] -= '0';
		if (s[i] % 2 == 0)
			check = true;
	}
	if (!check) {
		printf("-1");
		exit(0);
	}
	int mn = -1, mx = -1;
	forn(i, n - 1) {
		if (s[i] % 2 == 0 && s[i] < s[n - 1]) {
			mn = i;
			break;
		}
	}
	forn(i, n - 1)
		if (s[i] % 2 == 0)
			mx = i;
	if (mn == -1)
		swap(s[mx], s[n - 1]);
	else
		swap(s[mn], s[n - 1]);
	forn(i, n)
		s[i] += '0';
	cout << s;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define forn(i,n) for (int i = int(0); i < int(n); i++)
#define forb(i,n) for (int i = int(n-1); i >= int(0); i--)
#define for1(i,n) for (int i = int(1); i <= int(n); i++)
#define fore(i,a,n) for (int i = int(a); i < int(n); i++)

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define dist(x1, y1, x2, y2) sqrt(ld (sqr(x1 - x2) + sqr(y1 - y2)))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 501;
const int MAXN = 30001;
const int logn = 12;
const int inf = (int) 1e9;
const int alpha = 26;
const int my_hash = 31;
const long long base = (ll) 1e9;
const long long my_mod = 2674894331;
const long long l_inf = (ll) 4e18;
const long long mod = (ll) 1e9 + 7;
const long long l_mod = (ll) 1e18 - 11;
const double fi = (sqrt(5.0) + 1) / 2.0;
const double pi = acos(-1.0);
const double eps = 1e-8;
const double EPS = 0.00005;

int main() {
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = int(s.sz);
	bool check = false;
	forn(i, n) {
		s[i] -= '0';
		if (s[i] % 2 == 0)
			check = true;
	}
	if (!check) {
		printf("-1");
		exit(0);
	}
	int mn = -1;
	forn(i, n)
		if (s[i] % 2 == 0 && (mn == -1 || s[i] < s[mn]))
			mn = i;
	swap(s.back(), s[mn]);
	forn(i, n)
		s[i] += '0';
	cout << s;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define forn(i,n) for (int i = int(0); i < int(n); i++)
#define forb(i,n) for (int i = int(n-1); i >= int(0); i--)
#define for1(i,n) for (int i = int(1); i <= int(n); i++)
#define fore(i,a,n) for (int i = int(a); i < int(n); i++)

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define dist(x1, y1, x2, y2) sqrt(ld (sqr(x1 - x2) + sqr(y1 - y2)))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 501;
const int MAXN = 30001;
const int logn = 12;
const int inf = (int) 1e9;
const int alpha = 26;
const int my_hash = 31;
const long long base = (ll) 1e9;
const long long my_mod = 2674894331;
const long long l_inf = (ll) 4e18;
const long long mod = (ll) 1e9 + 7;
const long long l_mod = (ll) 1e18 - 11;
const double fi = (sqrt(5.0) + 1) / 2.0;
const double pi = acos(-1.0);
const double eps = 1e-8;
const double EPS = 0.00005;

int main() {
    ios_base::sync_with_stdio(0);
    string s, ans;
    cin >> s;
    int n = int(s.sz);
    bool check = false;
    forn(i, n) {
        s[i] -= '0';
        if (s[i] % 2 == 0)
            check = true;
    }
    if (!check) {
        printf("-1");
        exit(0);
    }
    int mn = -1;
    forn(i, n)
        if (s[i] % 2 == 0 && (mn == -1 || s[i] < s[mn]))
            mn = i;
    swap(s[n - 1], s[mn]);
    ans = s;
    swap(s[n - 1], s[mn]);
    if (s.back() % 2 == 0) {
        int mx = -1;
        forn(i, n - 1)
            if (mx == -1 || s[i] > s[mx])
                mx = i;
        swap(s[0], s[mx]);
        ans = max(ans, s);
    }
    forn(i, n)
        ans[i] += '0';
    cout << ans;
}


#include<iostream>
using namespace std;
int main()
{
	long n, k, count = 0, a[100001], temp;
	bool okay = false;
	cin >> n;
	k = n;
	while (k > 0)
	{
		k = k / 10;
		count++;
	}
	k = n;
	for (int i = count- 1; i >= 0; i--)
	{
		a[i] = k % 10;
		k = k / 10;
	}
	for (int i = count-2; i >=0; i--)
	{
		if (a[i] % 2 == 0)
		{
			temp = a[i];
			a[i] = a[count - 1];
			a[count - 1] = temp;
			okay = true;
			break;
		}
	}
	if (okay)
	{
		for (int i = 0; i < count; i++)
			cout << a[i];
	}
	else
		cout << -1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long n, k, count = 0, a[100001], temp;
	bool okay = false;
	cin >> n;
	k = n;
	while (k > 0)
	{
		k = k / 10;
		count++;
	}
	k = n;
	for (int i = count- 1; i >= 0; i--)
	{
		a[i] = k % 10;
		k = k / 10;
	}
	for (int i = 0; i < count; i++)
	{
		if (a[i] % 2 == 0)
		{
			temp = a[i];
			a[i] = a[count - 1];
			a[count - 1] = temp;
			okay = true;
			break;
		}
	}
	if (okay)
	{
		for (int i = 0; i < count; i++)
			cout << a[i];
	}
	else
		cout << -1;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	long long n, k, size = 0, index;
	string a;
	bool okay = false;
	cin >> a;
	size = a.length();
	for (long long i = 0; i < size; i++)
	{
		if ((a[i]-'0') % 2 == 0)
		{
			index = i;
			okay = true;
			if ((a[i]-'0') < (a[size - 1]-'0'))
			{
				break;
			}
		}
	}
	if (okay)
	{
		swap(a[index], a[size - 1]);
		cout << a;
	}
	else
		cout << -1;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long n, k, size = 0, a[100001], index;
	bool okay = false;
	cin >> n;
	k = n;
	while (k > 0)
	{
		k = k / 10;
		size++;
	}
	index = size + 1;
	k = n;
	for (int i = size - 1; i >= 0; i--)
	{
		a[i] = k % 10;
		k = k / 10;
	}
	for (int i = 0; i < size; i++)
	{
		if (a[i] % 2 == 0 )
		{
			index = i;
			okay = true;
			if (a[i] < a[size - 1])
			{
				break;
			}
		}
	}
	if (okay)
	{
		swap(a[index], a[size - 1]);
		for (int i = 0; i < size; i++)
			cout << a[i];
	}
	else
		cout << -1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long n, k, count = 0, a[100001], temp;
	bool okay = false;
	cin >> n;
	k = n;
	while (k > 0)
	{
		k = k / 10;
		count++;
	}
	k = n;
	for (int i = count- 1; i >= 0; i--)
	{
		a[i] = k % 10;
		k = k / 10;
	}
	for (int i = count-2; i >=0; i++)
	{
		if (a[i] % 2 == 0)
		{
			temp = a[i];
			a[i] = a[count - 1];
			a[count - 1] = temp;
			okay = true;
			break;
		}
	}
	if (okay)
	{
		for (int i = 0; i < count; i++)
			cout << a[i];
	}
	else
		cout << -1;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <string>
#include <ctime>
#include <set>
#include <functional>
#include <map>
#include <vector>
using namespace std;
char s[6];
int pos;

int main()
{
#ifdef _DEBUG
    clock_t tt;
    tt = clock();
    freopen("1.in", "rt", stdin);
    freopen("1.out", "wt", stdout);
#endif
    while(scanf("%s\n%", &s)!=EOF)
	{
		pos = -1;
		for(int i =0; i < strlen(s);++i)
		{
			if(s[i] == '0' || s[i] == '2' || s[i] == '4'||s[i] == '6'||s[i] == '8')
			{
				if(s[strlen(s)-1] < s[i])
				{
					pos = i;
					continue;
				}
				swap(s[i], s[strlen(s)-1]);
				printf("%s\n", s);
				return 0;
			}
		}
		if(pos > -1)
		{
			swap(s[pos], s[strlen(s)-1]);
			printf("%s\n", s);
			return 0;
		}
		printf("-1\n");
    }
#ifdef _DEBUG
    tt = clock() - tt;
    float time = ((float)tt) / CLOCKS_PER_SEC;
    std::cout << time;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <string>
#include <ctime>
#include <set>
#include <functional>
#include <map>
#include <vector>
using namespace std;
char s[6];

int main()
{
#ifdef _DEBUG
    clock_t tt;
    tt = clock();
    freopen("1.in", "rt", stdin);
    freopen("1.out", "wt", stdout);
#endif
    while(scanf("%s\n%", &s)!=EOF)
	{
		for(int i =0; i < strlen(*s);++i)
		{
			if(s[i] == '0' || s[i] == '2' || s[i] == '4'||s[i] == '6'||s[i] == '8')
			{
				swap(s[i], s[strlen(*s)-1]);
				printf("%s\n", s);
				return 0;
			}
		}
		printf("-1\n");
    }
#ifdef _DEBUG
    tt = clock() - tt;
    float time = ((float)tt) / CLOCKS_PER_SEC;
    std::cout << time;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <string>
#include <ctime>
#include <set>
#include <functional>
#include <map>
#include <vector>
using namespace std;
char s[6];

int main()
{
#ifdef _DEBUG
    clock_t tt;
    tt = clock();
    freopen("1.in", "rt", stdin);
    freopen("1.out", "wt", stdout);
#endif
    while(scanf("%s\n%", &s)!=EOF)
	{
		for(int i =0; i < strlen(s);++i)
		{
			if(s[i] == '0' || s[i] == '2' || s[i] == '4'||s[i] == '6'||s[i] == '8')
			{
				swap(s[i], s[strlen(s)-1]);
				printf("%s\n", s);
				return 0;
			}
		}
		printf("-1\n");
    }
#ifdef _DEBUG
    tt = clock() - tt;
    float time = ((float)tt) / CLOCKS_PER_SEC;
    std::cout << time;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <string>
#include <ctime>
#include <set>
#include <functional>
#include <map>
#include <vector>
using namespace std;
char s[100001];
int pos;

int main()
{
#ifdef _DEBUG
    clock_t tt;
    tt = clock();
    freopen("1.in", "rt", stdin);
    freopen("1.out", "wt", stdout);
#endif
    while(scanf("%s\n%", &s)!=EOF)
	{
		pos = -1;
		for(int i =0; i < strlen(s);++i)
		{
			if(s[i] == '0' || s[i] == '2' || s[i] == '4'||s[i] == '6'||s[i] == '8')
			{
				if(s[strlen(s)-1] < s[i])
				{
					pos = i;
					continue;
				}
				swap(s[i], s[strlen(s)-1]);
				printf("%s\n", s);
				return 0;
			}
		}
		if(pos > -1)
		{
			swap(s[pos], s[strlen(s)-1]);
			printf("%s\n", s);
			return 0;
		}
		printf("-1\n");
    }
#ifdef _DEBUG
    tt = clock() - tt;
    float time = ((float)tt) / CLOCKS_PER_SEC;
    std::cout << time;
#endif
    return 0;
}


#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
int y[100005]={};

int main (){
    string p;cin>>p;
    int R=p.size();
    for(int i=0;i<p.size();i++){
        y[i]=p[i]-'0';
        if(y[i]&&y[i]%2==0)R=i;
    }
    int min=8;
    int M=0;
    if(R!=p.size())min=y[R];
    if(R!=p.size()&&y[p.size()-1]%2){
        for(int i=R;i>=0;i--){
            if(y[i]%2==0){
                string Q=p;
                swap(Q[i],Q[p.size()-1]);
                int Y=0;
                for(int j=0;j<p.size();j++){
                    Y*=10;
                    Y+=Q[j]-'0';
                }
                if(M<Y)M=Y;

            }
        }
        swap(p[p.size()-1],p[R]);
        cout<<M<<endl;

    }
    else if(R==p.size()&&y[p.size()-1]%2)cout<<"-1"<<endl;
    else{
        string q=p;
        int max=0,min=9;
        for(int i=0;i<p.size()-1;i++){
            int x=p[i]-'0';
            if(x>max)max=i;
            if(x<min)min=i;
        }
        swap(q[max],q[min]);
        string N=p;
        max=0;
        for(int i=0;i<p.size()-1;i++){
            int x=p[i]-'0';
            int L=p[p.size()-1]-'0';
            if(x%2==0&&x>L){max=i;break;}
        }
        swap(N[max],N[p.size()-1]);
        int A=0,B=0;
        for(int i=0;i<p.size();i++){
            A*=10;B*=10;
            A+=q[i]-'0';B+=q[i]-'0';
        }
        if(B>A)A=B;
        cout<<A<<endl;
    }
    return 0;
}


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

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

using namespace std;

int main() {

	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int y=s[i]-'0';
		if(y%2==0&&y<s[s.size()-1]-'0'){
			swap(s[i],s[s.size()-1]);
			cout<<s<<endl;
			return 0;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		int y=s[i]-'0';
		if(y%2==0&&y>s[s.size()-1]-'0'){
			swap(s[i],s[s.size()-1]);
			cout<<s<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;

	return 0;
}


#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
int y[100005]={};

int main (){
    string p;cin>>p;
    int R=p.size();
    for(int i=0;i<p.size();i++){
        y[i]=p[i]-'0';
        if(y[i]&&y[i]%2==0)R=i;
    }
    int min=8;
    if(R!=p.size())min=y[R];
    if(R!=p.size()&&y[p.size()-1]%2){
        for(int i=0;i<p.size();i++){
            if(y[i]%2==0&&y[i]&&R<p.size()){
                if(y[i]<min){
                    R=i;
                }
            }
        }
        swap(p[p.size()-1],p[R]);
        cout<<p<<endl;

    }
    else if(R==p.size()&&y[p.size()-1]%2)cout<<"-1"<<endl;
    else{
        string q=p;
        int max=0,min=9;
        for(int i=0;i<p.size()-1;i++){
            int x=p[i]-'0';
            if(x>max)max=i;
            if(x<min)min=i;
        }
        swap(q[max],q[min]);
        string N=p;
        max=0;
        for(int i=0;i<p.size()-1;i++){
            int x=p[i]-'0';
            int L=p[p.size()-1]-'0';
            if(x%2==0&&x>L){max=i;break;}
        }
        swap(N[max],N[p.size()-1]);
        int A=0,B=0;
        for(int i=0;i<p.size();i++){
            A+=q[i]-'0';B+=q[i]-'0';
        }
        if(B>A)A=B;
        cout<<A<<endl;
    }
    return 0;
}


#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
using namespace std;
int y[100005]={};

int main (){
    string p;cin>>p;
    int R=p.size();
    for(int i=0;i<p.size();i++){
        y[i]=p[i]-'0';
        if(y[i]&&y[i]%2==0)R=i;
    }
    int min=8;
    if(R!=p.size())min=y[R];
    if(R!=p.size()&&y[p.size()-1]%2){
        for(int i=0;i<p.size();i++){
            if(y[i]%2==0&&y[i]&&R<p.size()){
                if(y[i]<min&&i<R){
                    R=i;
                }
            }
        }
        swap(p[p.size()-1],p[R]);
        cout<<p<<endl;

    }
    else if(R==p.size()&&y[p.size()-1]%2)cout<<"-1"<<endl;
    else{
        string q=p;
        int max=0,min=9;
        for(int i=0;i<p.size()-1;i++){
            int x=p[i]-'0';
            if(x>max)max=i;
            if(x<min)min=i;
        }
        swap(q[max],q[min]);
        string N=p;
        max=0;
        for(int i=0;i<p.size()-1;i++){
            int x=p[i]-'0';
            int L=p[p.size()-1]-'0';
            if(x%2==0&&x>L){max=i;break;}
        }
        swap(N[max],N[p.size()-1]);
        int A=0,B=0;
        for(int i=0;i<p.size();i++){
            A+=q[i]-'0';B+=q[i]-'0';
        }
        if(B>A)A=B;
        cout<<A<<endl;
    }
    return 0;
}


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

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

using namespace std;

int main() {

	string s;
	cin>>s;
	vector<string>p;
	for(int i=0;i<s.size();i++){
		int y=s[i]-'0';
		if(y%2==0){
			string h=s;
			swap(h[i],h[s.size()-1]);
			p.push_back(h);
		}
	}
	if(p.size()==0){
		cout<<-1<<endl;
		return 0;
	}
	sort(p.begin(),p.end());
	cout<<p[p.size()-1]<<endl;
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int a = s[s.size()-1]-'0';
    int lp = -1;

    for( int i = 0; i < s.size(); i++ )
    {
        if( (s[i]-'0') % 2 == 0 )
        {
            lp = i;
            if( s[i]-'0' < a )
            {
                char c = s[i];
                s[i]=s[s.size()-1];
                s[s.size()-1] = c;

                cout << s;
                return 0;
            }
        }
    }

    if( lp == -1 )
    {
        cout << -1;
    }
    else
    {
        char c = s[lp];
        s[lp]=s[s.size()-1];
        s[s.size()-1] = c;
    }

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int a = s[s.size()-1];
    int lp = -1;

    for( int i = 0; i < s.size(); i++ )
    {
        if( s[i]-'0' & 1 == 0 )
        {
            lp = i;
            if( s[i]-'0' < a )
            {
                switch(s[i],s[s.size()-1]);
                cout << s;
                return 0;
            }
        }
    }

    if( lp == -1 )
    {
        cout << -1;
    }
    else
    {
        switch(s[lp], s[s.size()-1]);
    }

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int a = s[s.size()-1]-'0';
    int lp = -1;

    for( int i = 0; i < s.size(); i++ )
    {
        if( s[i]-'0' & 1 == 0 )
        {
            lp = i;
            if( s[i]-'0' < a )
            {
                switch(s[i],s[s.size()-1]);
                cout << s;
                return 0;
            }
        }
    }

    if( lp == -1 )
    {
        cout << -1;
    }
    else
    {
        switch(s[lp], s[s.size()-1]);
    }

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int a = s[s.size()-1]-'0';
    int lp = -1;

    for( int i = 0; i < s.size(); i++ )
    {
        if( (s[i]-'0') % 2 == 0 )
        {
            lp = i;
            if( s[i]-'0' < a )
            {
                switch(s[i],s[s.size()-1]);
                cout << s;
                return 0;
            }
        }
    }

    if( lp == -1 )
    {
        cout << -1;
    }
    else
    {
        switch(s[lp], s[s.size()-1]);
    }

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int a = s[s.size()-1]-'0';
    int lp = -1;

    for( int i = 0; i < s.size(); i++ )
    {
        if( (s[i]-'0') % 2 == 0 )
        {
            lp = i;
            if( s[i]-'0' < a )
            {
                char c = s[i];
                s[i]=s[s.size()-1];
                s[s.size()-1] = c;

                cout << s;
                return 0;
            }
        }
    }

    if( lp == -1 )
    {
        cout << -1;
    }
    else
    {
        char c = s[lp];
        s[lp]=s[s.size()-1];
        s[s.size()-1] = c;
        cout << s;
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
string s;
int main()
{
	while(cin>>s)
	{
		int n=s.length();
		int odd=s[n-1]-'0';
		int flag=-1,i;
	 for(i=0;i<s.length();i++)
	 {
	 	int change=s[i]-'0';
	 	if(change%2==0)
	 	 {
		    flag=i;
	 	 	if(change<odd)
	 	 	{
              char a=s[i];
              s[i]=s[n-1];
              s[n-1]=a;

              break;
			}
	     }
	}
	if(i==n)
	{
		if(flag!=-1)
		{
			 char a=s[flag];
              s[flag]=s[n-1];
              s[n-1]=a;
		}
		else
		flag=-2;
	}
	if(flag==-2)
	cout<<-1<<endl;
	else
	cout<<s<<endl;
   }
  return 0;
 }


#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
string s;
int main()
{
	while(cin>>s)
	{
		int n=s.length();
		int odd=s[n-1]-'0';
		int flag=-1,i;
	 for(i=0;i<s.length();i++)
	 {
	 	int change=s[i]-'0';
	 	if(change%2==0)
	 	 {
		    flag=i;
	 	 	if(change<odd)
	 	 	{
              char a=s[i];
              s[i]=s[n-1];
              s[n-1]=a;

              break;
			}
	     }
	}
	if(i==n)
	{
		if(flag!=-1)
		{
			 char a=s[flag];
              s[flag]=s[n-1];
              s[n-1]=a;
		}
		else
		flag=-2;
	}
	if(flag==-2)
	cout<<-1<<endl;
	else
	cout<<s<<endl;
   }
  return 0;
 }


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}

if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0) continue;
    if((k[i]-'0')% 2 == 0){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            /*char s[6];
            for(int z = 0; z < k.length(); z++){
                s[z] = k[z];
            }
            int f = atoi(s);
            */
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0) continue;
    if((k[i]-'0')% 2 == 0){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}e
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
string ans = "";
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < n.length() - 1; i++){
    if(n[n.length()-1] - '0' == 0 && i == 0) continue;
    k = n;
    if((n[i] - '0') % 2 == 0 && n[i] != n[n.length()-1]){
        if(n[i] - '0' <= n[n.length() - 1]){
        k[i] = n[n.length()-1];
        k[n.length() - 1] = n[i];
        ans = k;
        break;
        }
    }
}

if(ans == ""){
    for(int i = n.length() - 1; i > -1 ; i--){
        if(i == 0 && n[n.length()-1] == '0') continue;
        if((n[i] - '0') % 2 == 0 && n[n.length()] != n[i]){
            ans = n;
            ans[i] = n[n.length() - 1];
            ans[n.length() - 1] = n[i];
            break;
        }
    }
}

if(ans == "") cout << -1;
else cout << ans;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if((k[i]-'0')% 2 == 0 && tmp != k[i]){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
string ans = "";
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < n.length() - 1; i++){
    if(n[n.length()-1] - '0' == 0 && i == 0) continue;
    k = n;
    if((n[i] - '0') % 2 == 0 && n[i] != n[n.length()-1]){
        if(n[i] - '0' <= n[n.length() - 1] - '0'){
        k[i] = n[n.length()-1];
        k[n.length() - 1] = n[i];
        ans = k;
        break;
        }
    }
}

if(ans == ""){
    for(int i = n.length() - 1; i > -1 ; i--){
        if(i == 0 && n[n.length()-1] == '0') continue;
        if((n[i] - '0') % 2 == 0 && n[n.length()] != n[i]){
            ans = n;
            ans[i] = n[n.length() - 1];
            ans[n.length() - 1] = n[i];
            break;
        }
    }
}

if(ans == "") cout << -1;
else cout << ans;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
string ans = "";
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < n.length() - 1; i++){
    k = n;
    if(n[n.length()-1] - '0' == 0) continue;
    if((n[i] - '0') % 2 == 0 && n[i] != n[n.length()-1]){
        k[i] = n[n.length()-1];
        k[n.length() - 1] = n[i];
        if(k > ans) ans = k;
    }
}

if(ans != "") cout << ans;
else cout << -1;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0) continue;
    if((k[i]-'0')% 2 == 0){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}e
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0) continue;
    if((k[i]-'0')% 2 == 0 && tmp != k[i]){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0 && i == 0) continue;
    if((k[i]-'0')% 2 == 0 && tmp != k[i]){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
string ans = "";
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < n.length() - 1; i++){
    if(n[n.length()-1] - '0' == 0 && i == 0) continue;
    k = n;
    if((n[i] - '0') % 2 == 0 && n[i] != n[n.length()-1]){
        if(n[i] - '0' <= n[n.length() - 1]){
        k[i] = n[n.length()-1];
        k[n.length() - 1] = n[i];
        ans = k;
        break;
        }
    }
}

if(ans == ""){
    for(int i = n.length() - 1; i > -1 ; i--){}
        if(i == 0 && n[n.length()-1] == '0') continue;
        if((n[i] - '0') % 2 == 0 && n[n.length()] != n[i]){
            ans = n;
            ans[i] = n[n.length() - 1];
            ans[n.length() - 1] = n[i];
            break;
        }
    }
}

if(ans == "") cout << -1;
else cout << ans;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0) continue;
    if((k[i]-'0')% 2 == 0){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

int main(){
string n,k;
cin >> n;
int cnt = 0;
int m = 0;
for(int i = 0; i < n.length() - 1; i++){
    if( (n[i] - '0') % 2 == 0) cnt++;
}
if(cnt == 0){
    cout << -1;
    return 0;
}

for(int i = 0; i < k.length() - 1; i++){
    k = n;
    char tmp = k[k.length() - 1];
    if(tmp - '0' == 0) continue;
    if((k[i]-'0')% 2 == 0){
            k[k.length() - 1] = k[i];
            k[i] = tmp;
            if(atoi(k.c_str()) > m) m = atoi(k.c_str());
    }
}
if(m == 0){
    cout << -1;
    return 0;
}
cout << m;

return 0;
}


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

	int main() {
		string n;
		cin >> n;
		int pos = 0;
		int l;
		bool f = true;
		for (int i = 0; i < n.size(); i++){
			if (n[i] == '0' || n[i] == '2' || n[i] == '4' || n[i] == '6' || n[i] == '8') {
				if (pos == 0 && n[i] < n[n.size()-1]){
					f = false;
					pos++;
					swap(n[i], n[n.size()-1]);
				}
				else {
					f = false;

					l = i;
				}
			}
		}
		if (f) {
			cout << "-1";
		}
		else {
			if (n[n.size()-1] == '0' || n[n.size()-1] == '2' || n[n.size()-1] == '4' || n[n.size()-1] == '6' || n[n.size()-1] == '8') {
				cout << n;
			}
			else {
				swap(n[l], n[n.size()-1]);
				cout << n;
			}
		}

	}


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

	int main() {
		int n;
		cin >> n;
		int p = 0;
		bool f = true;
		int pos = 0;
		int l;
		vector <int> k(6);
		while (n > 0) {
			k[p] = n % 10;
			n = n / 10;
			if (k[p] % 2 == 0) {
				f = false;
				if (pos == 0){
					l = p;
					pos++;
				}
			}
			if (n > 0){
				p++;
			}
		}
		pos = 0;
		if (f) {
			cout << "-1";
		}
		else {
			for (int i = p; i >= 0; i--){
				if (k[i] % 2 == 0 && k[i] < k[0] && pos == 0){
					swap(k[i], k[0]);
					pos++;
				}
			}
			if (pos == 0) {
				swap(k[l], k[0]);
			}
			for (int i = p; i >= 0; i--){
				cout << k[i];
			}
			}

	}