from sys import stdin

def main():
    input = stdin.readline

    N,M = map(int,input().split())

    s = [0] * M
    c = [0] * M

    ans = [None] * N
    for i in range(M):
        s[i], c[i] = map(int, input().split())

        if(ans[s[i]-1] is None):
            ans[s[i]-1] = c[i]
        elif(ans[s[i]-1] == c[i]):
            continue
        else:
            print("-1")
            return
    
    for i in range(N):
        if(ans[i] is None):
            ans[i] = 0
    
    ans_num = int(''.join(map(str,ans)))

    if(ans_num == 0)&(N > 1):
        print(-1)
    else:
        print(ans_num)

if __name__ == "__main__":
    main()