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