#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


int main(){
  std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N, M;
    cin >> N >> M;

    vector<int> ans;
    ans.resize(N,-1);

    bool ok = 0;
    rep(i,M){
      int s, c;
      cin >> s >> c;
      s--;
      if(ans[s]==-1) ans[s] = c;
      else{
        if(ans[s]!=c) ok = 1;
      }
    }

    rep(i,ans.size()) if(ans[i]==-1) ans[i]=0;
    int cnt = 0;
    rep(i,ans.size()){
      if(cnt== 0 && ans[i]==0) ok = 1;
      else if(ans[i]!=0) cnt++;
    }

    if(ok) cout << -1 << endl;
    else{
      rep(i,ans.size()) cout << ans[i];
      cout << endl;
    }
}