import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# -------------------------------
n, m = map(int, input().split())
ansList = [0] * n
#ansList = np.array(ansList)

for i in range(m):
    a, b = map(int, input().split())
    if (ansList[a - 1] == 0):
        ansList[a-1] = b
    else:
        if (ansList[a - 1] == b):
            pass
        else:
            print(-1)
            exit()


if (ansList[0] == 0):
    print(-1)
else:
    lis = map(str, ansList)
    ans = ''.join(lis)
    print(ans)
