#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x = 0;
  int a[3] = {0, 0, 0};
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if ((a[s[i] - 1] != 0 && a[s[i] - 1] != c[i]) || (s[i] == 1 && c[i] == 0)) {
      cout << "-1";
      x = 1;
      break;
    } else {
      a[s[i] - 1] = c[i];
    }
  }
  if (a[0] == 0) a[0] = 1;
  if (x == 0) {
    if (n == 1) {
      cout << a[0];
    }
    if (n == 2) {
      cout << a[0] << a[1];
    }
    if (n == 3) {
      cout << a[0] << a[1] << a[2];
    }
  }
  return 0;
}
