def main():
    n,m = map(int, input().split())
    S,C = [],[]
    for i in range(m):
        s,c = map(int, input().split())
        S.append(s)
        C.append(c)
    ans = ['0']*n
    for i in range(m):
        if S[i]==1 and C[i]==0:
            print(-1)
            return
        for j in range(i+1, m):
            if S[i] == S[j]:
                if C[i] != C[j]:
                    print(-1)
                    return
        ans[S[i]-1] = str(C[i])
    if len(ans)!=1 and ans[0] == '0':
        ans[0] = '1'
    ans = int(''.join(ans))
    print(ans)


if __name__ == '__main__':
    main()
