#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> box(n,10);
  int ans = 0;
  rep(i,m){
    int s;
    int c;
    cin >> s >>c;
    s--;
    if(s==0&&c==0&&n!=1) ans = -1;
    if(box[s]==c)continue;
    if(box[s]==10)box[s]=c;
    if(box[s]!=c)ans = -1;
  }
  if(n==1){
    if(ans==-1) cout << -1 << endl;
    else if(box[0]==10)cout << 0 << endl;
    else cout << box[0] << endl;
    return 0;
  }
  rep(i,n){
    if((i==0)&&box[i]==10)box[i]=1;
    if(box[i]==10)box[i]=0;
  }
  if(ans==-1)cout<<-1 <<endl;
  else {
    rep(i,n) cout << box[i];
    cout << endl;
  }
  return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
 
typedef long long ll;
const int MAXN=1e7+5;
 
int n,ans;
int deq[MAXN],l,r;
char s[MAXN],t[MAXN];
 
int main(){
 
    scanf("%d%s%s",&n,s+1,t+1);
    if(strcmp(s+1,t+1)==0) return puts("0"),0;
    l=1,r=0;
    for(int i=n,j=n;i>=1;i--){
        if(t[i]==t[i-1]) continue;
        j=min(i,j);
        while(j&&t[i]!=s[j]) j--;
        if(!j) return puts("-1"),0;
        while(l<=r){
            if(deq[l]-(r-l)>i) l++;
            else break;
        }
        deq[++r]=j;
        if(i!=j) ans=max(ans,r-l+1);
    }
    printf("%d",ans+1);
 
    fclose(stdin);
    fclose(stdout);
}