n, m = map(int, input().split())
s, c = [], []
import numpy as np


def main():
    for _ in range(m):
        tmp1, tmp2 = map(int, input().split())
        s.append(tmp1)
        c.append(tmp2)

    ans = np.zeros(n)

    kizon = {}
    flag = True
    for ss, cc in zip(s, c):
        if ss in kizon:
            if kizon[ss] != cc:
                flag = False
                break
        elif ss>n:
            flag = False
            break
        kizon[ss] = cc
        ans[ss-1] = cc

    if ans[0]==0:
        flag = False

    print('ans: ', ans)
    print('flag: ', flag)

    if flag:
        if len(ans)==3:
            print(int(ans[0]*100+ans[1]*10+ans[2]))
        elif len(ans)==2:
            print(int(ans[0]*10+ans[1]))
        else:
            print(int(ans[0]))
    else:
        print(-1)
        

if m==0:
    if n==1:
        print(1)
    elif n==2:
        print(10)
    else:
        print(100)

else:
    main()

