#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (n == 1 && m == 0) {
    cout << "0" << endl;
    return 0;
  }
  bool ok = true;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    x[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    if (x[s - 1] != -1 && x[s - 1] != c) {
      ok = false;
      break;
    }
    x[s - 1] = c;
  }
  if (!ok) {
    cout << "-1" << endl;
    return 0;
  }
  string result;
  if (m == 0) {
    result = "1";
    for (int i = 1; i < n; i++) {
      result += "0";
    }
    cout << result << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    result += (x[i] != -1) ? to_string(x[i]) : "0";
  }
  if (result.size() != n) {
    cout << "-1" << endl;
    return 0;
  }
  cout << result << endl;
  return 0;
}
