import sys


def main():
    input = sys.stdin.buffer.readline
    n, m = map(int, input().split())
    num = [0] * n
    reserved = [False] * n
    for _ in range(m):
        s, c = map(int, input().split())
        s -= 1
        if reserved[s]:
            if c != num[s]:
                print(-1)
                sys.exit()
        else:
            reserved[s] = True
            num[s] = c
    if num[0] == 0:
        print(-1)
    else:
        print("".join(list(map(str, num))))


if __name__ == "__main__":
    main()
