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