import math
import numpy as np
from collections import deque
def main():
    z = [int(t)for t in input().split()]
    n,m = z[0],z[1]

    sc = [[int(t)for t in input().split()] for _ in range(m)]
    sc = [(t[0]-1,t[1]) for t in sc]

    cond = set(sc)

    num = [-1]*n
    for s,c in cond:
        if num[s] == -1:
            num[s] = c
        else:
            print(-1)
            return
    
    if num[0] == 0:
        print(-1)
        return

    if num[0] == -1:
        num[0] = 1
    
    num = num[::-1]

    result = 0
    for i in range(n):
        result += 0 if num[i]==-1 else num[i]*10**i

    print(result)

if __name__ == "__main__":
    main()