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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

int main(){
  ll n,m;
  string s="0";
  cin>>n>>m;
  vector<pair<int,string>> v(m);
  rep(i,m){cin>>v[i].F>>v[i].S;}
  
  rep(i,n-1){s+="0";}
  rep(i,m){
  if(s[v[i].F-1]=='0'||s[v[i].F-1]==v[i].S[0]){
    s.replace(v[i].F-1,1,v[i].S);
  }
  else s="-1";
  }
  if(s[0]=='0'&&n!=1)s="-1";
  cout<<s<<endl;
return 0;
}