#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n);
  for (int i = (0); i < (n); ++i) {
    x[i] = -1;
  }
  int flag = 1;
  for (int i = (0); i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (x[s - 1] == -1 || x[s - 1] == c)
      x[s - 1] = c;
    else {
      flag = 0;
      break;
    }
  }
  if (x[0] == 0) flag = 0;
  if (flag) {
    for (int i = (0); i < (n); ++i) {
      if (x[i] == -1) x[i] = 0;
      cout << x[i];
    }
  } else
    cout << "-1";
  return 0;
}
