#include <bits/stdc++.h>
using namespace std;
const long long int INF = 10000000000000;
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<int> num(n, 0);
  bool ans = true;
  for (long long int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a > n) {
      ans = false;
      break;
    }
    if (a == 1 && b == 0) {
      ans = false;
      break;
    }
    if (num.at(a - 1) == 0)
      num.at(a - 1) = b;
    else if (num.at(a - 1) != b) {
      ans = false;
      break;
    }
  }
  if (n != 1 && num.at(0) == 0) num.at(0) = 1;
  if (ans) {
    for (long long int i = 0; i < n; i++) {
      cout << num.at(i);
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
