#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; i++) {
    int x = i;
    vector<int> v;
    while (x > 0) {
      v.push_back(x % 10);
      x /= 10;
    }
    if ((int)v.size() != N) continue;
    bool check = true;
    for (int j = 0; j < M; j++) {
      if (v[N - s[j]] != c[j]) {
        check = false;
        break;
      }
    }
    if (check) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
