ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m = mi()

    ans = [None] *n

    for i in range(m):
        s,c = mi()
        if((ans[s-1] == c) or (ans[s-1] == None)):
            ans[s-1] = c
        else:
            print('-1')
            return

    if(ans[0] == 0):
        if(len(ans) == 1):
            print(0)
            return
        else:
            print('-1')
            return

    
    ans2 = 0
    dec = 1
    for i in range(n-1,-1,-1):
        if(ans[i] == None):
            if(i == 0):
                ans[i] = 1
            else:
                ans[i] = 0
        ans2 += ans[i] * dec
        dec *= 10

    print(ans2)

if __name__ == "__main__":
    main()