#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  bool flag = true;
  cin >> N >> M;
  vector<int> ans(N);
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s.at(i);
    cin >> c.at(i);
    for (int j = 0; j < s.size(); ++j) {
      if (s.at(j) == s.at(i) && c.at(j) != c.at(i)) {
        flag = false;
        break;
      }
    }
    ans.at(s.at(i) - 1) = c.at(i);
  }
  if (N > 1) {
    int count = 0;
    for (int i = 0; i < ans.size(); ++i) {
      if (ans.at(i) == 0) {
        ++count;
      }
    }
    if (count == ans.size()) {
      flag = false;
    }
  }
  if (flag) {
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans.at(i);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
