
#include <bits/stdc++.h>
using namespace std;

int main()
{
    
    int n,m,i;
    cin>>n>>m;
    
    int s[m],c[m];
    int res[n+1]={0};
    
    bool flag = false;
    unordered_map<int,int>mp;
    for(i=0;i<m;i++){
        cin>>s[i]>>c[i];
        res[s[i]]=c[i];
    }
    
    for(i=0;i<n;i++){
        
        if(mp.find(s[i])!=mp.end()){
            if(mp[s[i]]!=c[i]){
                flag = true;
                break;
            }
        }
        else mp[s[i]]=c[i];
        
        if(s[i]==1 && c[i]==0  && n>1){
              flag = true;
                break;
        } 
    }
    
    if(res[1]==0 && n>1) flag = true;
   
    if(flag) cout<<"-1";
    else{
        int digit = 0;
        for(i=1;i<=n;i++) digit = digit*10+res[i];
        cout<<digit;
    }
        
    return 0;
}