#!/usr/bin/env python3
# input
n, m = map(int, input().split())
s = [-1 for _ in range(m)]
c = [-1 for _ in range(m)]
for i in range(m):
    s[i], c[i] = map(int, input().split())

# calc
# 重複があり、かつ、値が異なれば🙅
d = {}
for index, key in enumerate(s):
    if key not in d.keys():
        d[key] = c[index]
    else:
        if d[key] != c[index]:
            print(-1)
            exit(0)

# 0始まりは🙅
mi = min(list(d.keys()))
if d[mi] == 0:
    print(-1)
    exit(0)

# output
ans = ''
#import pdb; pdb.set_trace()
ma = max(list(d.keys()))
for i in range(1, n+1):
    if i in d.keys():
        ans += str(d[i])
    else:
        ans += '0' 
print(ans)
