#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1000000000000000000LL;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (1e5 + 1); i++) {
    string num = to_string(i);
    if (num.size() != n) continue;
    bool ok = false;
    for (int j = 0; j < (m); j++) {
      if (num[s[j] - 1] == c[j])
        ok = true;
      else {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
