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