#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];
  }
  int min = N == 1 ? 0 : pow(10, N - 1);
  for (int i = min; i < pow(10, N); i++) {
    int one = i >= 100 ? (int)(i / 100) : -1;
    int two = i >= 10 ? (int)(i / 10 % 10) : -1;
    int three = i % 10;
    vector<int> v;
    v.push_back(one);
    v.push_back(two);
    v.push_back(three);
    bool valid = true;
    for (int j = 0; j < M; j++) {
      if (v[s[j] - 1] != c[j]) {
        valid = false;
        break;
      }
    }
    if (valid) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
