import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n, m = map(int, input().split())
    d = [-1] * n
    for i in range(m):
        s, c = map(int, input().split())
        if d[s-1] != -1 and d[s-1] != c:
            print(-1)
            return
        d[s-1] = c
    ans = ''
    if n > 1 and (d[0] == -1 or d[0] == 0):
        print(-1)
        return
    for i in range(n):
        if d[i] == -1:
            d[i] = 0
        ans += str(d[i])

    print(ans)


main()
