#include <bits/stdc++.h>
using namespace std;
long long gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > a(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> a[i].first >> a[i].second;
  }
  vector<int> keta(n, 10);
  for (int i = 0; i < (int)(m); i++) {
    int tk = a[i].first - 1;
    if (keta[tk] != 10 && keta[tk] != a[i].second) {
      cout << "-1" << endl;
      return 0;
    } else {
      keta[tk] = a[i].second;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (keta[i] == 0 && n != 1) {
      cout << "-1" << endl;
      return 0;
    } else {
      if (keta[i] == 10) {
        if (i == 0 && n != 1) {
          keta[i] = 1;
        } else {
          keta[i] = 0;
        }
      }
    }
    cout << keta[i];
  }
}
