#include <bits/stdc++.h>
using namespace std;
int s[200005], c[200005], n, m;
int main() {
  cin >> n >> m;
  for (int i = (0); (i) < (m); (i)++) cin >> s[i] >> c[i];
  for (int i = (0); (i) < (4005); (i)++) {
    bool pd = 1;
    string ch = to_string(i);
    if (ch.size() != n) break;
    for (int j = (0); (j) < (m); (j)++) {
      if (ch[s[j] - 1] != c[j] + '0') pd = 0;
    }
    if (pd) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
