#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n, -1);
  bool d = false;
  for (long long int i = 0; i < (m); ++i) {
    int t, u;
    cin >> t >> u;
    if (s[t - 1] != -1 && s[t - 1] != u) {
      d = true;
    }
    s[t - 1] = u;
  }
  if (d) {
    cout << -1 << endl;
    return 0;
  }
  string ans = "";
  bool f = true;
  for (long long int i = 0; i < (n); ++i) {
    if (s[i] == -1) {
      ans += '0';
    } else {
      ans += to_string(s[i]);
    }
  }
  int dd = 0;
  int t = stoi(ans);
  while (t > 0) {
    t /= 10;
    dd++;
  }
  if (dd != n) {
    cout << -1 << endl;
  } else {
    cout << stoi(ans) << endl;
  }
  return 0;
}
