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
    # if not(flag) and (v == "@" or v == '0'):
    #     print(-1)
    #     sys.exit(0)
    if (v == "@" or v == '0'):
        res[i] = '0'

# flag = False
# for i in res:
#     if i != '0':
#         flag = True
#     elif not(flag) and i == '0':
#         print(-1)
#         sys.exit(0)
res2 = ""
for i in res:
    res2 += i

try:
    res2 = int(res2)
except:
    print(-1)
    sys.exit(0)

if len(str(res2)) == n:
    print(res2)
else:
    print(-1)
