#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int digit = n;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int start = std::pow(10.0, (float)(digit - 1));
  int ans = 0;
  for (int i = start; i < start * 10; i++) {
    std::string str = std::to_string(i);
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (str[s[j] - 1] != (char)((c[j]) + '0')) {
        ok = false;
        break;
      }
    }
    if (ok == true) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
