#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T>
using V = vector<T>;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;
int main() {
  int n, m;
  cin >> n >> m;
  Vi seisu(n, -1);
  for (int(i) = 0; (i) < (m); (i)++) {
    int s, c;
    cin >> s >> c;
    if (seisu[s - 1] > 0 && seisu[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    seisu[s - 1] = c;
  }
  if (seisu[0] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int(i) = 0; (i) < (n); (i)++) cout << ((seisu[i] == -1) ? 0 : seisu[i]);
  cout << endl;
  return 0;
}
