#include <bits/stdc++.h>
using namespace std;
int keta(int a) {
  int n = 1;
  while (a >= 10) {
    a /= 10;
    n++;
  }
  return n;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  int kmax = pow(10, n);
  vector<int> s(kmax + 3);
  for (int i = 0; i < kmax; i++) s[i] = -1;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (s[a] == -1)
      s[a] = b;
    else if (s[a] == b)
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  string an;
  if (s[1] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (s[1] == -1)
    an += "1";
  else
    an += to_string(s[1]);
  for (int k = 2; k <= n; k++) {
    if (s[k] == -1)
      an += "0";
    else
      an += to_string(s[k]);
  }
  cout << an << endl;
}
