#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  vector<bool> flag(n, false);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (!flag.at(s) || c == v.at(s)) {
      v.at(s) = c;
      flag.at(s) = true;
    } else {
      cout << "-1" << endl;
      return 0;
    }
    if (n > 1 && v.at(s) == 0 && flag.at(s)) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans = 0;
  if (n == 1) ans = v.at(0);
  if (n == 2) ans = v.at(0) * 10 + v.at(1);
  if (n == 3) ans = v.at(0) * 100 + v.at(1) * 10 + v.at(2);
  cout << ans << endl;
  return 0;
}
