#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  int ans = -1;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    vector<int> digit(3);
    digit[2] = i % 10;
    digit[1] = ((i % 100) - (i % 10)) / 10;
    digit[0] = ((i % 1000) - (i % 100)) / 100;
    bool a = true;
    for (int j = 0; j < M; j++) {
      if (digit[s[j] - 1 + (3 - N)] != c[j]) a = false;
    }
    if (a) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
