#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < 1000; ++i) {
    int d = 0, now = i;
    ;
    while (now > 0) {
      ++d;
      now /= 10;
    }
    if (n != d) {
      continue;
    }
    int f = 1;
    for (int j = 0; j < m; ++j) {
      int t = i;
      for (int k = 0; k < max(0, n - s[j]); ++k) {
        t /= 10;
      }
      t %= 10;
      if (t != c[j]) {
        f = 0;
      }
    }
    if (f == 1) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
