#include <bits/stdc++.h>
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psl = pair<string, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vi S(M);
  vc C(M);
  for (int i = int(0); i < int(M); ++i) {
    cin >> S[i] >> C[i];
    S[i]--;
  }
  map<int, char> mp;
  for (int i = int(0); i < int(M); ++i) {
    int d = N - 1 - S[i];
    if ((mp.count(d) > 0 && mp[d] != C[i]) || (d < 0 || N <= d)) {
      cout << -1 << endl;
      return 0;
    }
    mp[d] = C[i];
  }
  string ans = "";
  for (int i = int(0); i < int(N); ++i) {
    ans = mp[i] + ans;
  }
  if ((ans[0] == '0' && ans.size() > 1) || (ans.size() != N)) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
