#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(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (ans.at(s.at(i) - 1) > c.at(i) || c.at(i) > 0)
      ans.at(s.at(i) - 1) = c.at(i);
  }
  if (ans.at(0) == 0) {
    cout << -1;
    return 0;
  }
  int a = 0;
  for (int i = 0; i < n; i++) {
    a += ans.at(i) * pow(10, n - 1 - i);
  }
  cout << a;
  return 0;
}
