#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m, 0), c(m, 0);
  vector<int> ans(m, 0);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (ans.at(s.at(i) - 1) != 0 && ans.at(s.at(i) - 1) != c.at(i)) {
      cout << -1;
      return 0;
    }
    ans.at(s.at(i) - 1) = c.at(i);
  }
  reverse(ans.begin(), ans.end());
  if (ans.at(m - 1) == 0) {
    cout << -1;
    return 0;
  }
  if (ans.at(m - 1) == 0 && ans.at(m - 2) == 0) {
    cout << -1;
    return 0;
  }
  int a = 0;
  for (int i = m - 1; i >= 0; i--) {
    a += ans.at(i) * pow(10, i);
  }
  cout << a;
}
