#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-9;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  bool fl = true;
  vector<int> vec(n, 0);
  vec.at(0) = 1;
  vector<int> che(n, 0);
  for (int(i) = 0; (i) < (int)(m); i++) {
    int a, b;
    cin >> a >> b;
    che.at(a - 1)++;
    if (che.at(a - 1) == 1) {
      vec.at(a - 1) = b;
    } else {
      if (vec.at(a - 1) != b) {
        fl = false;
      }
    }
  }
  if (n >= 2 && vec.at(0) == 0) {
    fl = false;
  }
  if (fl) {
    for (int(i) = 0; (i) < (int)(n); i++) {
      cout << vec.at(i);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
