#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int j = 0; j < M; j++) {
    cin >> s[j] >> c[j];
  }
  for (int i = 0; i < 1000; i++) {
    vector<int> num;
    int cnt = 0;
    int n = i;
    while (n != 0) {
      num.push_back(n % 10);
      n /= 10;
    }
    if (num.size() != N) {
      continue;
    }
    reverse(num.begin(), num.end());
    for (int j = 0; j < M; j++) {
      if (num[s[j] - 1] == c[j]) {
        cnt++;
      }
    }
    if (cnt == M) {
      for (int x : num) {
        cout << x;
      }
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
