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

//省略形
#define rep(i,n) for(auto i=0; i<n ; ++i)
#define REP(i,a,b) for(auto i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//よく使う定数
const int INF = 1e9;
const int MOD = 1e9+7;
//逆元
const int INV = 1e9+5;

//UnionFindTree
struct union_find{
  vector<int> data;
  union_find(int size) : data(size , -1) { }

  void merge(int x , int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(data[y] < data[x]) swap(x , y);
    data[x] += data[y];
    data[y] = x;
    return; 
  }

  bool same(int x , int y){
    x = root(x) , y = root(y);
    return x == y;
  }

  int root(int x){
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }

  int size(int x){
    return -data[root(x)];
  }
};

//プロトタイプ宣言
void faster(void);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);
template <class T>
T modpow(T , T , T);

//メモ
//最大公約数:__gcd　|　最小公倍数:__lcm


int main(){
  faster();
  int n,m;
  cin >> n >> m;
  vi s(m) , c(m);
  rep(i,m) cin >> s[i] >> c[i];
  rep(i,m){
    rep(j,m){
      if(s[i]==s[j] && c[i]!=c[j]){
        cout << -1;
        return 0;
      }
    }
    if(s[i]==1 && c[i]==0 && n!=1){
      cout << -1;
      return 0;
    }
  }
  string s1,s2,s3;
  int cnt1=0,cnt2=0,cnt3=0;
  rep(i,m){
    if(s[i]==1){
      s1=to_string(c[i]);
      cnt1++;
    }
    if(s[i]==2){
      s2=to_string(c[i]);
      cnt2++;
    }
    if(s[i]==3){
      s3=to_string(c[i]);
      cnt3++;
    }
  }
  if(cnt1==0) s1="1";
  if(cnt2==0) s2="0";
  if(cnt3==0) s3="0";
  if(cnt1==0&&n==1) cout << 0;
  if(n==1) cout << s1;
  if(n==2) cout << s1+s2;
  if(n==3) cout << s1+s2+s3;
}


























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//繰り返し自乗法
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//繰り返し自乗法(剰余)
template <class T>
T modpow(T x , T y , T mod){
  if(y == 0) return 1;
  if(y%2 == 1){
    ll temp = modpow(x,y-1,mod);
    return temp*x%mod;
  }
  else{
    ll temp = pow_mod(x,y/2,mod);
    return temp*temp%mod;
  }
}

