import sys

input = sys.stdin.readline

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

if M == 0:
    ans = 0
    if N == 2:
        ans = 10
    if N == 3:
        ans = 100
    print(ans)
    exit()

sc = []
dic = dict()
for _ in range(M):
    sc.append(list(map(int, input().split())))

sc.sort(key=lambda x:x[0])

if sc[-1][0] > N:
    print(-1)
    exit()

for i in range(M):
    if sc[i][0] not in dic.keys():
        dic[sc[i][0]] = sc[i][1]
    elif dic[sc[i][0]] != sc[i][1]:
        print(-1)
        exit()

if N == 1:
    if sc[0][0] == 1 and sc[0][1] == 0:
        print(0)
        exit()
else:
    if sc[0][0] == 1 and sc[0][1] == 0:
        print(-1)
        exit()

ans = ['a'] * N

try:
    for i in range(M):
        ans[sc[i][0]-1] = sc[i][1] 
except:
    print(-11)
    exit()

if ans[0] == 'a':
    ans[0] = 1
if ans[1] == 'a':
    ans[1] = 0
if ans[2] == 'a':
    ans[2] = 0 

out = ""
for i in range(N):
    out += str(ans[i])

print(int(out))