# coding: utf-8
def main():
    n, m = map(int, input().split())
    N = ['a']*n
    for i in range(m):
        s, c = map(int, input().split())
        if N[s-1] == 'a':
            N[s-1] = c
        elif N[s-1] != c:
            print(-1)
            quit()
    if n != 1 and N[0] == 0:
        print(-1)
        quit()
    else:
        for c in N:
            if c == 'a':
                print(0,end="")
            else:
                print(c,end="")
        
    

if __name__ == '__main__':
    main()