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