def mapt(fn, *args):
    return tuple(map(fn, *args))
  
def main():
    n, m = mapt(int, input().split(" "))
    numbers = [False] * 3
    # print(numbers)
    for _ in range(m):
        s, c = mapt(int, input().split(" "))
        s -= 1
        if numbers[s] == False: numbers[s] = c
        else: continue

    # print(numbers)
    new_one = [0 if i==False else i for i in numbers]
    # print(new_one)
    new_one = int("".join(mapt(str, new_one)))
    # print(new_one)
    if len(str(int(new_one)))== n:
        print(new_one)
    else:
        print("-1")

main()