from operator import itemgetter
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = [0]*max(s)
    ans[0] = 1
    for i in range(M):
        if s[i]-1 == 0:
            if ans[0] == 1 or ans[0] == c[i]:
                ans[0] = c[i]
            else:
                ans = "-1"
                break
        if ans[s[i]-1] == 0 or ans[s[i]-1] == c[i]:
            ans[s[i]-1] = c[i]
        else:
            ans = "-1"
            break
    if ans == "-1":
        ans == "-1"
    else:
        ans = list(map(str,ans))
        if ans == ["0"]:
            print("-1")
        else:
            print(*ans,sep="")

if __name__ == '__main__':
    main()