#include <bits/stdc++.h>
using namespace std;
int main() {
  int flag = 0;
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  vector<int> hanbetu(m);
  vector<int> k(n);
  for (int i = 0; i < (int)(m); i++) cin >> s.at(i) >> c.at(i);
  for (int i = 0; i < (int)(m); i++) {
    k.at(s.at(i) - 1) = c.at(i);
    hanbetu.at(i) = s.at(i) * 10 + c.at(i) * 1;
  }
  for (int i = 0; i < m - 1; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s.at(i) == s.at(j)) {
        if (hanbetu.at(i) != hanbetu.at(j)) flag = 1;
      }
    }
  }
  if (n != 1 && k.at(0) == 0) flag = 1;
  if (flag == 0) {
    for (int i = 0; i < (int)(n); i++) cout << k.at(i);
    cout << endl;
  } else
    cout << "-1" << endl;
}
