#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  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) {
      ok = false;
      break;
    }
    x[s - 1] = c;
  }
  if (!ok) {
    cout << "-1" << endl;
    return 0;
  }
  int result = 0;
  for (int i = n - 1; i >= 0; i--) {
    result *= 10;
    result += (x[i] != -1) ? x[i] : 0;
  }
  cout << result << endl;
  return 0;
}
