def resolve():
    n, m = map(int, input().split())
    d = {}
    for i in range(m):
        a, b = map(int, input().split())
        if a in d and b != d[a]:
            print(-1)
            return
        d[a] = b
    if n > 1 and (1 in d) and d[1] == 0:
        print(-1)
        return
    ans = list(str(10 ** (n - 1)))
    for i in range(n):
        if i + 1 in d:
            ans[i] = str(d[i + 1])
    print("".join(ans))


if __name__ == '__main__':
    resolve()
