import math
import sys
def main():
    n, m = map(int, input().split())
    a = [[0 for i in range(2)] for j in range(m)]
    for i in range(m):
        a[i] = list(map(int, input().split()))

    ans = [0 for i in range(n)]
    count = 0

    for _, contents in enumerate(a):
        if contents[0] == 1 and contents[1] == 0:
            print(-1)
            sys.exit()
        else:
            ans[contents[0]-1] = contents[1]

        #同じ場所に矛盾がないか
        
        for i , contents_2 in enumerate(a):
                if contents[0] == contents_2[0] and contents[1] != contents_2[1]:
                    count += 1
                    if count == 2:
                        print(-1)
                        sys.exit()
    ans = map(str, ans)

    print(int(''.join(ans)))

if __name__ == '__main__' :
    main()