# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    SC = [list(map(int,input().split())) for i in range(M)]
    #print(N,M,SC)
    ans = []
    for _ in range(N):
        ans.append(-1)
    #print(ans)
    for j in range(M):
        if ans[SC[j][0]-1] == -1  or ans[SC[j][0]-1] == SC[j][1]:
            ans[SC[j][0]-1] = SC[j][1]
        else:
            print('-1')
            return
    for k in range(N):
        if ans[k]==-1:
            ans[k]=0
        print(ans[k],end = '')
    #print(''.join(str(ans)))
if __name__ == '__main__':
    main()