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

dic = {}
ans = [0 for _ in range(N)]
for _ in range(M):
    s, c = map(int, input().split())
    if dic.get(s) is not None:
        if dic.get(s) != c:
            print("-1")
            break
        else:
            if dic.get(s) > c:
                dic[s] = c
    else:
        dic.setdefault(s, c)
        ans[s-1] = c
else:
    if (N > 1) and (ans[0] == 0):
        print("-1")
    else:
        print(''.join(str(i) for i in ans))