#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c[100000], s[1000000], ans[10000] = {0}, aannss = 0;
  vector<int> a, b;
  cin >> n >> m;
  for (long long i = 0; i < (m); i++) {
    cin >> c[i] >> s[i];
    a.push_back(c[i]);
    b.push_back(s[i]);
    if (c[i] == 1 && s[i] == 0) {
      cout << -1;
      return 0;
    }
    int x;
    for (long long k = 0; k < (a.size()); k++)
      if (a[k] == a[i]) break;
    if (x != a.size() - 1) {
      if (b[i] == b[x])
        ;
      else {
        cout << -1;
        return 0;
      }
    }
    ans[i + 1] = b[i + 1];
  }
  while (n--) {
    aannss *= 10;
    aannss += ans[n];
  }
  cout << aannss;
  return 0;
}
