Harryxun/stf_run huggingface dataset:
def num_of_1bit(n: int)->int:
    s = 0
    while n > 0:
        s += n & 1
        n >>= 1
    return s


def diff_by_1_bit(N: int, A: int, B: int)->list:
    num_A = num_of_1bit(A)
    num_B = num_of_1bit(B)
    if abs(num_A - num_B) == 1:
        raise Exception('')
    else:
        return []


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = diff_by_1_bit(N, A, B)
    if len(ans) == 0:
        print('NO')
    else:
        print('YES')
        print(' '.join(map(str, ans)))


### FIXED CODE ###

def num_of_1bit(n: int)->int:
    '''n の立っているビットを数えます。
    :param n: number
    :return: number of 1 bit
    '''
    s = 0
    while n > 0:
        s += n & 1
        n >>= 1
    return s


def diff_idx(a: int, b: int)->int:
    '''a と b のビット列を比較してビットの状態が異なる最小の
    インデックスを返します。ここで、インデックスは 2^i の i 
    に対応する。
    :param a: number 1
    :param b: number 2
    :return: index
    '''
    if a == b:
        return -1
    idx = 0
    while a > 0 or b > 0:
        if a & 1 != b & 1:
            break
        idx += 1
        a, b = a >> 1, b >> 1
    return idx


def remove_bit(n: int, idx: int)->int:
    '''n の idx 番目のビットを消去します。idx は 2^idx に対
    応します。
    ex) n = 1011011, idx = 2
    -> 101111

    :param n: number
    :param idx: index
    :return: number removed `idx`th bit
    '''
    upper = (n >> (idx+1)) << idx
    lower = n & ((1 << idx) - 1)
    return upper | lower


def insert_bit(n: int, idx: int, bit: bool)->int:
    '''n の idx 番目にビットを挿入します。
    ex) n = 101111, idx = 2, bit = True
    -> 1011111
    '''
    upper = (n >> idx) << (idx + 1)
    lower = n & ((1 << idx) - 1)
    insert = bit << idx
    return upper | insert | lower


def route(_from: int, to: int, N: int)->list:
    '''_from から to に至る N ビットの数を全て使ったルートを
    計算します。
    :param _from: start
    :param to: end
    :param N: number of bit
    :return: routes
    '''
    if N == 1:
        return [_from, to]

    di = diff_idx(_from, to)

    a = remove_bit(_from, di)
    b = remove_bit(to, di)
    c = a ^ 1

    from_bit = (_from & (1 << di)) != 0
    to_bit = (to & (1 << di)) != 0

    first_half = map(lambda x: insert_bit(x, di, from_bit), route(a, c, N-1))
    second_half = map(lambda x: insert_bit(x, di, to_bit),  route(c, b, N-1))

    return list(first_half) + list(second_half)


def diff_by_1_bit(N: int, A: int, B: int)->list:
    num_A = num_of_1bit(A)
    num_B = num_of_1bit(B)
    if abs(num_A - num_B) % 2 == 0:
        return []

    return route(A, B, N)


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = diff_by_1_bit(N, A, B)
    if len(ans) == 0:
        print('NO')
    else:
        print('YES')
        print(' '.join(map(str, ans)))
s = input()
n = nt(input())
for i in range(n):
    order, a, b, *c = input().split()
    if order == 'replace':
        s = s[:a] + c + s[b+1:]
    elif order[o] == 'r':
        s = s[:a] + a[a:b+1:-1] + a[b+1:]
    else:
        print(s)


### FIXED CODE ###

s = input()
n = int(input())
for i in range(n):
    order, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if order == 'replace':
        s = s[:a] + c[0] + s[b+1:]
    elif order[0] == 'r':
        s = s[:a] + s[::-1][len(s)-b-1:len(s)-a]+ s[b+1:]
    else:
        print(s[a:b+1])
import math

x = int(input())
ans = [1]
s = int(math.sqrt(x))
if s >= 2:
    for i in range(2,s+1):
        temp = i
        while True:
            temp *= i
            if temp <= n:
                ans.append(temp)
            else:
                break

print(max(ans))

### FIXED CODE ###

import math

x = int(input())
ans = [1]
s = int(math.sqrt(x))
if s >= 2:
    for i in range(2,s+1):
        temp = i
        while True:
            temp *= i
            if temp <= x:
                ans.append(temp)
            else:
                break

print(max(ans))
N = int(input())
P = [int(input().split()) for i in range(N)]
Q = [int(input().split()) for i in range(N)]
 
data = [i+1 for i in range(N)]
 
def listExcludedIndices(data, indices=[]):
  return [x for i, x in enumerate(data) if i not in indices]
 
def count(res,p):
    count = 0
    for i in range(len(res)):
        count +=1
        if res[i] == p:
            break
    return count
result = []
for i in range(len(data)):
  for j in range(len(data)-1):
    for k in range(len(data)-2):
      jData = listExcludedIndices(data, [i])
      kData = listExcludedIndices(jData, [j])
      result.append([data[i], jData[j], kData[k]])
print(abs(count(result,P) - count(result,Q)))

### FIXED CODE ###

N = int(input())
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())

import itertools
L = list(itertools.permutations(list(range(1,N+1))))
print(abs(L.index(Q) - L.index(P)))
def main():
    a, b, c = map(int, input().split())
    count = 0
    while (a | b | c) & 1 == 0:
        if a==b==c:
            print(-1)
            return
        a, b, c = (b + c) >> 1, (c + a) >> 1, (a + b) >> 1
        count += 1
        print(a,b,c)
    
    print(count)

while True:
    main()


### FIXED CODE ###

def main():
    a, b, c = map(int, input().split())
    if a == b == c:
        print(0 if a & 1 else -1)
        return
    count = 0
    while (a | b | c) & 1 == 0:
        a, b, c = (b + c) >> 1, (c + a) >> 1, (a + b) >> 1
        count += 1
    
    print(count)
 
main()
n,m = map(int,input().split())
A = set([int(input()) for _ in range(m)])
mod = 1000000007
dp = [0]*(n+1)
dp[0],dp[1] = 1,1
for i in range(2,n+1):
    dp[i] = (dp[i-1] + dp[i-2])
    if i in a:dp[i] = 0
print(dp[n])

### FIXED CODE ###

n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:dp[i]=0
print(dp[n])
import math
a = int(input())
b = float(input())
print(math.floor(a*b))


### FIXED CODE ###

import decimal
Deci = decimal.Decimal

a, b = input().split()
x, y = Deci(a), Deci(b)
ans = int(x * y)
print(ans)
L, R = input().split()
s = (R-1) // (L-1)
ans = s + 1
print()

### FIXED CODE ###

L, R = map(int, input().split())
s = (R - 1) // (L - 1)
r = (R - 1) % (L - 1)
if r == 0:
  ans = s
else:
  ans = s + 1
print(ans)
N = int(input())
A = list(map(int, input().split()))
res = 1

if 0 in A :
    print(0)
    exit()

for x in range(N) :
    res = res*A[x]
    if res > 10E+17
        res = -1
        break

print(res)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

limit = 10 ** 18
A.sort()
result = A[0]
for a in A[1:]:
    result *= a
    if result > limit:
        print(-1)
        exit()
print(result)
h,w = map(int,input().split())
for i in range(w):
    print("#",end="")
print("")
for i in range(h):
    a = input()
    print("#" + a + "#")

for i in range(w):    
    print("#",end=")

### FIXED CODE ###

h,w = map(int,input().split())
for i in range(w+2):
    print("#",end="")
print("")
for i in range(h):
    a = input()
    print("#" + a + "#")

for i in range(w+2):    
    print("#",end="")
n = int(input())
a = [0] * 10**5
for x in range(1, 101):
	for y in range(1, 101):
		for z in range(1, 101):
			a[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
for i in range(1, n + 1):
	print(a[i])

### FIXED CODE ###

l, r, d = [int(x) for x in input().split()]
print(r // d - (l - 1) // d)
r = input()

print(r^2)

### FIXED CODE ###


r = int(input())

r2 = int(r**2)

print(r2)
import sys #追加

n=int(input())
sys.setrecursionlimit(10**5*2)

s=input()
x=int(s,2)
ans=[]

ans_memo=[0]*(2**(n+1))
#print(ans_memo)
#ans_memo[1]=1
#ans_memo[2]=1

def DEF(x,cnt):
    global ans_memo
    #print(x,cnt,ans_memo)
    if ans_memo[x]!=0:
        return ans_memo[x]
    else:
        if x%(str(bin(x)).count("1"))==0:
            ans_memo[x]=1
            return 1
        else:
            tmp=DEF(x%(str(bin(x)).count("1")),cnt+1)+1
            ans_memo[x]=tmp
            return tmp

ans=[]

for i in range(n):
    tmp=2**(n-i-1)
    tmp_num=x

    #1の時
    if tmp&tmp_num:
        tmp_num-=tmp
        ans.append(DEF(tmp_num,0))
        
    else:
        tmp_num+=tmp
        ans.append(DEF(tmp_num,0))

#print(ans_memo)

for item in ans:
    print(item)
            









### FIXED CODE ###

def popcount(x):
    return bin(x).count("1")

n=int(input())
s=input()
X=int(s,2)

one_cnt=popcount(X)

modp=X%(one_cnt+1)
modm=X%(one_cnt-1) if one_cnt-1!=0 else 0

for i in range(n):
    if s[i]=="1":
        if one_cnt-1==0:
            print(0)
            continue
        else:
            num=(modm-pow(2,n-i-1,one_cnt-1))%(one_cnt-1)
    else:
        num=(modp+pow(2,n-i-1,one_cnt+1))%(one_cnt+1)

    #print(i,"num",num)
    cnt=1
    while num!=0:
        num=num%popcount(num)
        cnt+=1
    print(cnt)
import sys
sys.setrecursionlimit(10 ** 5 + 10)
from numba import jit
def input(): return sys.stdin.readline().strip()

@njit
def resolve():
    
    n,k=map(int,input().split())
    A=list(map(int,input().split()))+[0]

    m=n
    log = 0
    while m >= 2:
        m = m // 2
        log += 1
    from itertools import accumulate

    for i in range(min(k,n*2*log+1)):
        B=[0]*(n+1)

        for j in range(n):
            val=A[j]
            #if val==0: continue
            B[max(0,j-val)]+=1
            B[min(n,j+val+1)]-=1
        A=list([0]+list(accumulate(B)))[1:]
    
    

    print(*A[:-1])    
    
    
resolve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,k=map(int,input().split())
    A=list(map(int,input().split()))

    for i in range(k):
        B=[0]*(n+1)

        for j in range(n):
            val=A[j]
            B[max(0,j-val)]+=1
            B[min(n,j+val+1)]-=1
        
        for k in range(n):
            B[k+1]+=B[k]
        A=B[:-1]

        if A==[n]*(n):
            break
    
    

    print(*A)    
    
resolve()
from collections import Counter

N = int(input())
V = list(map(int, input().split()))

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
x3, c3 = Counter(V1).most_common(2)[1]
x4, c4 = Counter(V2).most_common(2)[1]
if x1 == x2:
    a = max(c1+c4, c2+c3)
    print(N-a)
else:
    print(N - c1 - c2)

### FIXED CODE ###

from collections import Counter

N = int(input())
V = list(map(int, input().split()))

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
if x1 == x2:
    if c1 > c2:
        x2, c2 = Counter(V2).most_common(2)[1]
    elif c1 < c2:
        x1, c1 = Counter(V1).most_common(2)[1]
    elif c1 == c2 == N // 2:
        c1, c2 = N//2, 0
    else:

        x2, c2 = Counter(V2).most_common(2)[1]
        x3, c3 = Counter(V1).most_common(2)[1]
        c2 = max(c2, c3)

print(N - c1 - c2)
from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)


listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)

s=Counter(a)
for i in s.keys():
  lists_=[-1*s[i]]*n
  lists_[i-1]=0
  lists=np.array(lists_)
  listn=listn+lists

#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')

### FIXED CODE ###

from collections import Counter
import numpy as np
n,k,q=map(int,input().split())
a=[]
for i in range(q):
  a_=int(input())
  a.append(a_)
 
 
listn_=[]
for i in range(n):
  listn_.append(k)
listn=np.array(listn_)
listn=listn-q
s=Counter(a)
for i in s.keys():
  listn[i-1]+=s[i]
 
#print(listn)
for i in listn:
  if i>0:
    print('Yes')
    
  else:
    print('No')
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [list(map(int, readline().split())) for _ in range(n)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] -= 1
    ls = [0] * n
    ql = collections.deque()
    for i in range(n):
        ql.append([0, i])

    for i in range(10 ** 10):
        fq = [True] * n
        while ql:
            d, ps = ql.popleft()
            if d == i:
                if ls[ps] < n - 1 and fq[ps] and fq[nw]:
                    nw = a[ps][ls[ps]]
                    rw = a[nw][ls[nw]]
                    if ps == rw:
                        ls[ps] += 1
                        ql.append([d+1, ps])
                        ls[nw] += 1
                        ql.append([d+1, nw])
                        fq[nw] = False
                fq[ps] = False
            else:
                ql.appendleft([d, ps])
                break
        if len(ql) == 0:
            print(i + 1 if sum(ls) == n * (n - 1) else -1)
            exit()


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ad = [0] * n
    dq = collections.deque([[0, i + 1] for i in range(n)])
    for i in range(10 ** 15):
        fd = {}
        while True:
            if len(dq) != 0:
                d, q = dq.popleft()
                q -= 1
                if d <= i:
                    if ad[q] < n - 1:
                        qq = a[q][ad[q]] - 1
                        tq = a[qq][ad[qq]] - 1
                        if q == tq and qq not in fd and tq not in fd:
                            ad[qq] += 1
                            ad[tq] += 1
                            if ad[qq] < n - 1:
                                dq.append([d + 1, qq + 1])
                            if ad[tq] < n - 1:
                                dq.append([d + 1, tq + 1])
                            fd[qq] = 0
                            fd[tq] = 0
                else:
                    dq.append([d, q + 1])
                    break
            else:
                break
        if len(dq) == 0:
            b = True
            for v in ad:
                if v != n - 1:
                    b = False
                    break
            if b:
                print(i + 1)
                exit()
            else:
                print(-1)
                exit()


if __name__ == '__main__':
    slove()
import numpy as np

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a += [list(map(int, input().split()))]
for i in range(m):
    b += [int(input())]
a = np.array(a)
b = np.array(b)
b.reshape(4, 1)

c = np.dot(a, b)
for i in range(len(c))
    print(c[i])



### FIXED CODE ###

n, m = map(int, input().split())
A = [input().split() for _ in range(n)]
b = [input()for _ in range(m)]
for a in A:
    print(sum(int(x)*int(y) for x, y in zip(a,b)))
import math
n,x=map(int,input().split())
print(3*(n-math.gcd(n,x)))


### FIXED CODE ###

from fractions import gcd
n,x=map(int,input().split())
print(3*(n-gcd(n,x)))
import sys
for s in sys.stdin:
    while 1:
        p　=　s.find("@")
        if p==-1:　break
        s　=　s.replace(s[p:p+3],　s[p+2]　*　int(s[p+1]))
    print s[:-1]

### FIXED CODE ###

import sys
for s in sys.stdin:
    while 1:
        p = s.find("@")
        if p==-1: break
        s = s.replace(s[p:p+3], s[p+2] * int(s[p+1]))
    print s[:-1]
t = input()

l = [_ for i in range(len(t))]
for i in range(0, len(t)):
    if t[i] =="?":
        l[i] = "D"
    
    else:
        l[i] = t[i]

print("".join(l))

### FIXED CODE ###

t = input()

l = ["" for i in range(len(t))]
for i in range(0, len(t)):
    if t[i] =="?":
        l[i] = "D"
    
    else:
        l[i] = t[i]

print("".join(l))
N = int(input())
list = [int(input()) for i in range(n)]
c = 0
x = 1
while x != 2 and c < N:
    x = list[x - 1]
    c += 1
if x == 2:
    print(c)
else:
    print(-1)


### FIXED CODE ###

N = int(input())
list = [int(input()) for i in range(N)]
c = 0
x = 1
while x != 2 and c < N:
    x = list[x - 1]
    c += 1
if x == 2:
    print(c)
else:
    print(-1)
a, b, c = map(int, input().split())
ans = 0
for i range(1, a+1):
    N = [int(x) for x in str(i)]
    sum = sum(N)
    if b <= sum and sum <= c:
        ans += sum

print(ans)


### FIXED CODE ###

a, b, c = map(int, input().split())
ans = 0
for i in range(1, a+1):
    N = [int(x) for x in str(i)]
    sum_N = sum(N)
    if (b <= sum_N and sum_N <= c):
        ans += i

print(ans)
a=int(input())
s=input()
t=s if a>=3200 else red
print(t)

### FIXED CODE ###

a=int(input())
s=input()
t=s if a>=3200 else "red"
print(t)
t=list(input())
ans = 0
for i in range(len(t)):
	if i != 0 and i != len(t)-1:
		if t[i] == "?":
			if t[i-1] == "P":
				t[i] = "D"
			elif t[i+1] == "D" or "?":
				t[i] = "P"
			else:
				t[i] = "D"
	elif i==0:
		if t[i] == "?":
			if t[i+1] == "D" or "?":
				t[i] = "P"
			else:
				t[i] = "D"
	else:
		if t[i] == "?":
			t[i] = "D"
print("".join(t))

### FIXED CODE ###

t=list(input())
ans = 0
if len(t) != 1:
	for i in range(len(t)):
		if i != 0 and i != len(t)-1:
			if t[i] == "?":
				if t[i-1] == "P":
					t[i] = "D"
				elif t[i+1] == "D" or t[i+1] == "?":
					t[i] = "P"
				else:
					t[i] = "D"
		elif i==0:
			if t[i] == "?":
				if t[i+1] == "D" or t[i+1] == "?":
					t[i] = "P"
				else:
					t[i] = "D"
		else:
			if t[i] == "?":
				t[i] = "D"
else:
	if t[0] == "?":
		t[0] = "D"
print("".join(t))
nums=input()
print(nums.count(1))

### FIXED CODE ###

number=list(map(int,input()))
print(number.count(1))
n = int(input())
s = input()

i = 0
ans = 0

while i < len(s):
    if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
        ans += 1
        i += 3
    else:
        i += 1
print(ans)



### FIXED CODE ###

n = int(input())
s = input()

i = 0
ans = 0

while i < len(s) - 2:
    if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
        ans += 1
        i += 3
    else:
        i += 1
print(ans)
import resource, sys
resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())

class Union_Find:
    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def find(self,x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def unite(self, x, y):
        if self.rank[x] == self.rank[y]:
            self.parent[y] = x
            self.rank[x] += 1
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y

uftree = Union_Find(N+1)

for i in range(M):
    x, y, _ = map(int, input().split())
    uftree.unite(x, y)

result = 0
for i in range(1, N+1):
    if uftree.find(i) == i:
        result += 1

print(result)



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
paths = [[] for _ in range(N)]

for _ in range(M):
    a, b, z = map(int, input().split())
    paths[a-1].append(b-1)
    paths[b-1].append(a-1)

visited = [False] * N

def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node)
count = 0
for i in range(N):
    if visited[i] == False:
        count += 1
        dfs(i,-1)

print(count)
N, M = [int(_) for _ in input().split()]
P = [0] + [int(_) for _ in input().split()]
XY = sorted([sorted([int(_) for _ in input().split()]) for _ in range(M)],
            key=lambda xy: -xy[0] - N * xy[1])

UF = list(range(N + 1))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = min(UF[x], find(y))
    UF[UF[y]] = UF[x]


def same(x, y):
    return find(x) == find(y)


for x, y in XY:
    unite(x, y)

ans = 0
for i in range(1, N + 1):
    if same(i, P[i]):
        ans += 1
print(ans)


### FIXED CODE ###

N, M = [int(_) for _ in input().split()]
P = [0] + [int(_) for _ in input().split()]
XY = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    UF[find(x)] = find(y)


def same(x, y):
    return find(x) == find(y)


for x, y in XY:
    unite(x, y)

ans = 0
for i in range(1, N + 1):
    if same(i, P[i]):
        ans += 1
print(ans)
n,m = map(int, input().split())
sc=[list(map(int,input().split())) for i in range(m)]
s=[]
c=[]
f=0
ans=[str(0) for i in range(n)]
for i in range(m):
    if sc[i][0]==1 and sc[i][1]==0 and n!=1:
        f=-1
        break
    else:
        if sc[i][0] in s:
            if sc[i][1]!=c[s.index(sc[i][0])]:
                f=-1
                break
        else:
            ans[sc[i][0]-1]=str(sc[i][1])
            s.append(sc[i][0])
            c.append(sc[i][1])
if c(s.index(0))==0 and n!=1:
    f=-1
    
if f==-1:
    print(-1)
else:
    if n==1:
        print(''.join(ans))
    else:
        if ans[0]==str(0):
            ans[0]==str(1)
        print(''.join(ans))


### FIXED CODE ###

N,M=map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
a=str(0)*N
A=[a[i] for i in range(len(a))]
x=0
#print(sc)
b=[]
c=[]
for i in range(M):
    if (sc[i][0] == 1) and (sc[i][1]==0) and (N!=1):
        x=-1
        break
    else:
        if (sc[i][0]) in b:#左から何桁目の情報が既にある場合、既に登録されているその桁の値と新たに登録しようとしてるその桁の値が異なるとき弾く
            if sc[i][1]!=int(c[b.index(sc[i][0])]):
                #print(c[b.index(sc[i][0])])
                x=-1
                break
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
            c.append(sc[i][1])
if x==-1:
    print(-1)      
elif b==[] and (N!=1):
    if N==2:
        print(10)
    elif N==3:
        print(100)
elif (1 not in b) and(N!=1):
    A[0]=str(1)
    a="".join(A)
    print(a)
elif  (1 not in b) and (2 not in b) and (N==3):
    A[0]=str(1)
    A[1]=str(0)
    a="".join(A)
    print(a)

else:
    a="".join(A)
    print(a)