#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1000000007;
int dig(int n) {
  int nn = n, r = 0;
  while (nn) {
    nn /= 10;
    r++;
  }
  if (n == 0) r++;
  return r;
}
int main() {
  int n, m;
  cin >> n >> m;
  int d[3] = {10, 10, 10};
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] != 10 && d[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    d[s - 1] = c;
  }
  if (d[0] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (d[0] == 10) {
    d[0] = 1;
  }
  for (int i = 0; i < n; i++) cout << (d[i] == 10 ? 0 : d[i]);
  cout << endl;
}
