n, m = map(int, input().split())
num = [0]*n

for _ in range(m):
    s, c = map(int, input().split())
    if num[s-1] != 0:
        if num[s-1] == c:
            continue
        else:
            print(-1)
            exit()
    else:
        num[s-1] = c

ans = ''.join(map(str, num))
if len(str(int(ans))) == n:
    print(ans)
else:
    print(-1)
