n, m = map(int, input().split())
ans = ["0"]*n
if(m==0 and n==1):print(0);exit()
for i in range(m):
    a, b = map(int, input().split())
    if(ans[a-1] == "0"):ans[a-1] = str(b)
    elif(int(ans[a-1]) > b):ans[a-1] = str(b)
if(ans[0] == "0"):print(-1)
else:print("".join(ans))