#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int i;
  int si, ci;
  vector<int> ansv;
  for (i = 0; i < n; i++) ansv.push_back(-1);
  for (i = 0; i < m; i++) {
    cin >> si >> ci;
    if (ansv[si - 1] == -1 | ansv[si - 1] == ci)
      ansv[si - 1] = ci;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ansv[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (ansv[0] == -1) ansv[0] = 1;
  for (i = 1; i < n; i++)
    if (ansv[i] == -1) ansv[i] = 0;
  int ansi = 0;
  for (i = 0; i < n; i++) {
    ansi += ansv[i] * pow(10, n - i - 1);
  }
  cout << ansi << endl;
  return 0;
}
