n,m = [int(i) for i in input().split()]
num = ['0' for i in range(n)]
flg = 0
for i in range(m):
    s,c = [i for i in input().split()]
    place = int(s)-1
    if num[place]=='0':
        num[place] = c
    elif num[place]==c:
        pass
    else:
        flg = 1
        break

if num[0] != '0' and flg==0:
    print(''.join(num))
else:
    print(-1)