# c = list(map(int, input().split()))
# a, b, c = map(int, input().split())
# a = [list(map(int, list(input()))) for i in range(n)]
import sys
n, m = map(int, input().split())
l = {}

ret = ['-1'] * n

for i in range(0, m):
    v = list(map(int, input().split()))
    if v[0] in l and l[v[0]] != v[1]:
        print(-1)
        sys.exit()
    
    if v[0] not in l or l[v[0]] > v[1]:
        l[v[0]] = v[1]

for j, k in l.items():
    ret[j - 1] = str(k)

for i in range(len(ret)):
    if ret[i] == '-1':
        if i == 0:
            if n == 1:
                ret[0] = '0'
            else:
                ret[0] = '1'
        else:
            ret[i] = '0'
if n != 0 and ret[0] == '0':
    print(-1)
else:
    print("".join(ret))
