import sys
n, m = map(int, input().split())
s = [0 for i in range(m)]
c = [0 for i in range(m)]

res = list("@" * n)

for i in range(m):
    s[i], c[i] = map(str, input().split())
    s[i] = int(s[i]) - 1
    # print(min(res[s[i]], c[i]))
    if res[s[i]] == "@" or res[s[i]] == c[i]:
        res[s[i]] = c[i]
    else:
        print(-1)
        sys.exit(0)


flag = False
for i, v in enumerate(res):
    if v != '0' and v != "@":
        flag = True
    elif not(flag) and (v == "@" or v == '0'):
        print(-1)
        sys.exit(0)
    if flag and (v == "@" or v == '0'):
        res[i] = '0'

for i in res:
    print(i, end='')
print()
