#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000;
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];
    s[i]--;
  }
  int roop = 1;
  for (int i = 0; i < n; ++i) {
    roop *= 10;
  }
  for (int i = roop / 10; i < roop; i++) {
    string S = to_string(i);
    bool isans = true;
    for (int j = 0; j < m; ++j) {
      if (S[s[j]] != c[j]) {
        isans = false;
      }
    }
    if (isans) {
      cout << S << endl;
      return 0;
    }
  }
  if (n == 1) {
    string S = to_string(0);
    bool isans = true;
    for (int j = 0; j < m; ++j) {
      if (S[s[j]] != c[j]) {
        isans = false;
      }
    }
    if (isans) {
      cout << S << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
