n, m = [int(x) for x in input().split()]
dict = {}
flg = True
for i in range(m):
    s, c = [int(x) for x in input().split()]
    if s in dict.keys() and dict[s] != c:
        flg = False
        break
    else:
        dict[s] = c
for i in range(1, n + 1):
    if not i in dict.keys():
        dict[i] = 0
if dict[1] == 0:
    flg = False
res = 0
if flg:
    for i in range(1, n + 1):
        res += dict[i] * 10 ** (n - i)
print(res if flg else -1)
