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