def main():
    n, m = map(int, input().strip().split())
    target = [0, 0, 0]
    stored = [False, False, False]
    logic_err = [False, False, False]
    for i in range(m):
        s, c = map(int, input().strip().split())
        tmp = c * 10**(m-s)
        if (stored[s-1]==True) and (target[s-1]!=tmp):
            logic_err[s-1] = True
        elif (tmp==0) and (n>1) and (s==1):
            logic_err[s-1] = True
        else:
            target[s-1] = tmp
            stored[s-1] = True

    if sum(x==True for x in logic_err)>0:
        print(-1)
    else:
        print(sum(target))

main()
