#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 num = 0; num <= 1000; num++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (to_string(num)[S[i] - 1] != C[i]) ok = false;
    }
    if (ok) {
      cout << num << endl;
      return 0;
    }
  }
  puts("-1");
}
