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 d[min(d)] == 0:
        print(-1)
        return
    ans = ""
    for i in range(n):
        ans += str(d[i + 1]) if i + 1 in d else "0"
    print(int(ans))


if __name__ == '__main__':
    resolve()
