#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
bool judge(int i, int m, vector<int> &s, vector<int> &c) {
  for (int j = 0; j < m; j++) {
    if (to_string(i)[s[j] - 1] - '0' != c[j]) return false;
  }
  return true;
}
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 = 1; i <= 999; i++) {
    if (to_string(i).length() == n) {
      if (judge(i, m, s, c)) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
