#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> S(m);
  vector<int> C(m);
  for (int i = 0; i < m; i++) cin >> S[i] >> C[i];
  for (int i = 702; i < 703; i++) {
    string st = to_string(i);
    for (int j = 0; j < m; j++) {
      bool jud = true;
      if (st[S[j] - 1] != (char)C[j] + '0') jud = false;
      if (jud == true) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
