import sys
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    ts,tc = map(int,input().split()) 
    s.append(ts)
    c.append(tc)
ans = [0]*n
c_ans = [0]*n

if m==0:
    print(-1)
    sys.exit()

if m > n:
    print(-1)
    sys.exit()

for i in range(m):
    if c_ans[s[i]-1] == 1:
        if ans[s[i]-1] != c[i]:
            print(-1)
            sys.exit()
    else:
        c_ans[s[i]-1] = 1
        ans[s[i]-1] = c[i]
ans = list(map(str,ans))
# print("".join(ans))
ans = "".join(ans)
ans = int(ans)
# print(ans)
# print(len(str(ans)))
if len(str(ans)) != n:
    print(-1)
    sys.exit()
print(ans)
