import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    sc = [tuple(map(int, input().split())) for _ in range(M)]

    for i in range(10 ** N):
        v = str(i)
        l = len(v)
        for s, c in sc:
            if s > l or int(v[s-1]) != c:
                break
        else:
            print(i)
            exit()
    print(-1)
    
if __name__ == '__main__':
    main()
