from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    SC = set(tuple(map(int, input().split())) for _ in [0] * M)

    num = [-1] * (N + 1)
    for s, c in SC:
        if num[s] < 0:
            num[s] = c
        else:
            print(-1)
            return
    n = ''
    if num[1] < 0:
        num[1] = 1
    for i in num[1:]:
        if i < 0:
            n += '0'
        else:
            n += str(i)
    if n[0] == '0' and len(n) > 1:
        print(-1)
    else:
        print(n)


main()
