import sys

n,m = [int(i) for i in input().split()]
num = ['0' for i in range(n)]

s = []
c = []

for _ in range(m):
    s0, c0 = [i for i in input().split()]
    s.append(s0)
    c.append(c0)
for i in range(len(s)):
    if s[i]=='1' and c[i]=='0':
        print(-1)
        sys.exit()
    for j in range(i+1, len(s)):
        if s[i]==s[j]:
            if c[i]!=c[j]:
                print(-1)
                sys.exit()


for i in range(m):
    place = int(s[i])-1
    if num[place]=='0':
        num[place] = c[i]
    elif num[place]==c[i]:
        pass
    else:
        print(-1)
        sys.exit()

if len(''.join(num))==len(num):
    print(''.join(num))
else:
    print(-1)