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