#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  // 10^18 くらいまでいける

// for DP
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1LL << 60;

int main(){
  int n, m;
  cin >> n >> m;

  vector<pair<int, char>> sc(m);
  rep(i, m)cin >> sc[i].first >> sc[i].second;

  int max_v = pow(10, n);
  bool flag=false;
  string tmp;

  // debug(max_v);

  for (int i=0; i<max_v; i++){
    tmp = to_string(i);

    if (tmp.size() != n)
      continue;

    // debug(tmp);
    for (int j=0; j<m; j++){  
      // debug(sc[j].first);
      // debug(sc[j].second);
      if (tmp[sc[j].first-1] == sc[j].second)
        flag=true;
      else
        flag = false;

      if (!flag)
        break;
    }

    if (flag){
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}
