#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  bool f = true;
  for (int i = 0; i < 1000; i++) {
    V v;
    for (int j = i; j; j /= 10) v.push_back(j % 10);
    if (v.size() != n) continue;
    reverse(v.begin(), v.end());
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (v[s[j] - 1] != c[j]) f = false;
    }
    if (f) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
