#!/usr/bin/env python
# coding: utf-8

# In[20]:


N, M = map(int, input().split())
sc = []
for _ in range(M):
    sc.append(list(map(int, input().split())))


# In[21]:


flag = True
ans = [-1]*N
for i,x in enumerate(sc):
    if ans[x[0]-1] == -1:
        ans[x[0]-1] = x[1]
    else:
        if ans[x[0]-1] != x[1]:
            flag = False
            break
if flag:
    if ans[0] != 0:
        ans = [x if x != -1 else 0 for x in ans]
        print("".join(list(map(str,ans))))
    else:
        print(-1)
else:
    print(-1)


# In[ ]:




