import sys

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()

n,m = get_ints()
mydict = dict()
Arr = ['0']*n
flag = 0
for i in range(m):
    s,x = get_ints()
    if s in mydict and mydict[s]!=x:
        flag = 1
    mydict[s] = x
    Arr[s-1] = str(x)

if flag==1:
    print(-1)
    exit()
if Arr[0]=='0' and len(Arr)>1:
    print(-1)
    exit()
print(''.join(Arr))