#include <bits/stdc++.h>
using namespace std;
template <class T>
T sq(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
vector<pair<int, int> > sc;
int number[4];
int main() {
  int n, m, s, c;
  cin >> n >> m;
  int flg = 1, flg1 = 0;
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    if (number[s] > c or number[s] == 0) {
      number[s] = c;
    }
    if (s == 1) {
      if (c != 0 or n == 1) flg1 = 1;
    }
  }
  if (!flg1) {
    number[1] = 1;
  }
  if (number[n] == 0) flg = 0;
  if (flg) {
    for (long long i = 1; i <= n; i++) {
      cout << number[i];
    }
    cout << "\n";
  } else
    cout << -1 << "\n";
  return 0;
}
