import sys
import math
input = sys.stdin.readline

# int = int(input())
# s = input().split()
# i = list(map(int, input().split()))
# s = [input() for i in range(3)]

s = list(map(int, input().split()))
n = s[0]
m = s[1]

d = [-2, -2, -2, -2]

if n == 1:
    d[1] = -1
if n == 2:
    d[1] = -1
    d[2] = -1
if n == 3 :
    d[1] = -1
    d[2] = -1
    d[3] = -1

flag = True
for i in range(m):
    sc = list(map(int, input().split()))
    s = sc[0]
    c = sc[1]

    if d[s] == -2:
        flag = False
        break
    elif d[s] == -1:
        if c == 0 and n != 1:
            flag = False
            break
        d[s] = c
    elif d[s] != c:
        flag = False
        break

if flag == False:
    print(-1)
else:
    if d[1] == -1:
        d[1] = 1
    if d[2] == -1:
        d[2] = 0
    if d[3] == -1:
        d[3] = 0
    
    ans = 0
    ans+=d[1]
    if n == 1:
        print(ans)
    ans*=10
    ans+=d[2]
    if n == 2:
        print(ans)
    ans*=10
    ans+=d[3]
    if n == 3:
        print(ans)




