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