# c = list(map(int, input().split()))
# a, b, c = map(int, input().split())
# a = [list(map(int, list(input()))) for i in range(n)]

n, m = map(int, input().split())
l = {}

ret = list("0" * n)

for i in range(0, m):
    v = list(map(int, input().split()))
    if v[0] == 1 and v[1] == 0:
        continue

    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)

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