def resolve():
    n, m = map(int, input().split())
    ans = [-1] * n
    for _ in range(m):
        s, c = map(int, input().split())
        if ans[s - 1] not in (-1, c):
            print(-1)
            return
        ans[s - 1] = c
    if ans[0] == 0 and n != 0:
        print(-1)
        return
    print("".join([str(x) if x > 0 else "0" for x in ans]))


if __name__ == '__main__':
    resolve()
