#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int gcd(int a, int b) {
  if (a < b) {
    int t = a;
    a = b;
    b = t;
  }
  while (b != 0) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}
int factorial(ll n) {
  if (n > 0) {
    return n * factorial(n - 1);
  } else
    return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> mg(m);
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > n) {
    }
    mg[a[i] - 1] = b[i];
  }
  for (int i = 0; i < m; i++) {
    if (mg[a[i] - 1] != b[i]) {
      if (mg[a[i] - 1] > b[i]) mg[a[i] - 1] = b[i];
    }
  }
  if (n == 1 and mg[0] == 0) {
    cout << "0";
    return 0;
  } else if (mg[0] == 0) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < m; i++) cout << mg[i];
}
