#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,i;
    cin>>n;
    int m;cin>>m;
    vchar a(n);
    int pos,val;
    for(i=0;i<a.size();i++) a[i]='b';
    bool f1=0,f2=0;
    while(m--){
        cin>>pos>>val;
        if(val>0) f1=1;
        char c=val+'0';
        if(a[n-pos]=='b') {
            a[n-pos]=c;
        }
        else if(a[n-pos]!=val){f2=1;break;}
        else {
            a[n-pos]=c;
        }
    }
    reverse(a.begin(), a.end()); 
  if(!f2 && f1){
    for(i=0;i<n;i++){
        if(a[i]=='b') a[i]='0';
        cout<<a[i];
    }}
    else cout<<-1;
    return 0;
}


