#include <bits/stdc++.h>
using namespace std;
int n;
int m;
vector<int> s;
vector<int> c;
bool ok(string str) {
  int len = str.length();
  if (len != n) return false;
  for (int i = 0; i < m; ++i) {
    if (str[s[i]] != (char)(c[i] + '0')) return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 1; i < 1000; ++i) {
    if (ok(to_string(i))) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
