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