#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] >= 0 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  if (v[0] < 0) v[0] = 1;
  if (v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    ret *= 10;
    ret += max(0, v[i]);
  }
  cout << ret << endl;
  return 0;
}
