#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;
    if (v[n - s] == -1) {
      v[n - s] = c;
    } else {
      if (v[n - s] == c)
        continue;
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (v[n - 1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == -1) {
      v[i] = 0;
    }
    res += v[n - 1 - i] * pow(10, n - 1 - i);
  }
  cout << res << endl;
}
