def main():
    n,m = map(int, input().split())
    lim = 10 ** n
    val = [list(map(int, input().split())) for _ in range(m)]
    ans = 1001
    for i in range(10**(n-1) if n >= 2 else 0, lim):
        cnt = 0
        for j in val:
            k = j[0]-1
            l = str(i)
            if l[k] == str(j[1]):
                cnt += 1
                if cnt == m:
                    ans = min(ans,i)
    if ans == 1001:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()