#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i <= m - 1; ++i) {
    cin >> s[i] >> c[i];
  }
  string hoge;
  int ans = -1;
  for (int i = 1; i <= 1000; ++i) {
    hoge = to_string(i);
    if (hoge.size() != n) continue;
    bool flag = true;
    for (int j = 0; j <= m - 1; ++j) {
      if (hoge[s[j] - 1] - '0' != c[j]) flag = false;
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
