#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = str(10**(n-1)-1)
ans = ["0"]*n
for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i,s in enumerate(s_len):
    if ans[s-1] == "0" or ans[s-1] == str(c_len[i]):
        ans[s-1] = str(c_len[i])
    else:
        print("-1")
        exit()

if int("".join(ans)) > int(dig):
    print("".join(ans))
elif int(dig) == 0 and int("".join(ans)) == 0:
    print("0")
else:
    print("-1")