n, m, *s_c = map(int, open(0).read().split())

for i in range(0, m * 2 , 2):
    s_c[i] -= 1

num = [-1] * n
flag = False
for i in range(m):
    if num[s_c[2 * i]] != -1 and num[s_c[2 * i]] != s_c[2 * i + 1]:
        print("diffrent")
        flag = True
    else:
        num[s_c[2 * i]] = s_c[2 * i + 1]
        
for i in range(n):
    if num[i] == -1:
        num[i] = 0
        
#print(num)
    
if 1 < n and num[0] == 0:
    print("head is 0")
    flag = True

if flag:
    print(-1)
else:
    print(''.join([str(n) for n in num]))