#include <bits/stdc++.h>
using namespace std;
bool use[3];
int main() {
  int d[3];
  int n, m;
  cin >> n >> m;
  int s, c;
  bool flag = true;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (s == 0 and c == 0) {
      flag = false;
      break;
    } else if (s > n) {
      flag = false;
      break;
    } else if (use[s] and c != d[s]) {
      flag = false;
      break;
    } else {
      d[s] = c;
      use[s] = true;
    }
  }
  if (n != 1 and !use[0])
    d[0] = 1;
  else {
    for (int i = 0; i < n; i++) {
      if (!use[s]) d[s] = 0;
    }
  }
  if (!flag)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) {
      cout << d[i];
    }
    cout << endl;
  }
  return 0;
}
