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