#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, T b);
template <class T>
bool chmin(T& a, T b);
int* eratosthenes(int N);
bool bit_search(int pattern, int N);
void initialize(void);
const long long int INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K>
struct P {
  T a;
  K b;
};
int main(void) {
  initialize();
  int N, M;
  cin >> N >> M;
  vector<int> vec(N, -1);
  for (int i = (0); i < (M); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (vec[a] == -1 || vec[a] == b) {
      vec[a] = b;
    } else {
      cout << "-1\n";
      return 0;
    }
  }
  if (vec[0] == 0 && N != 1) {
    cout << "-1\n";
    return 0;
  }
  if (vec[0] == -1) vec[0] = 1;
  for (auto v : vec) {
    if (v == -1)
      cout << 0;
    else
      cout << v;
  }
  cout << "\n";
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int* eratosthenes(int N) {
  int* prime_array = new int[N + 1];
  int lim = N;
  prime_array[0] = 0;
  prime_array[1] = 0;
  for (int i = (2); i < (N + 1); i++) {
    prime_array[i] = 1;
  }
  for (int i = (2); i < (lim); i++) {
    if (prime_array[i] == 0) continue;
    lim = N / i;
    for (int j = i * 2; j < N + 1; j += i) {
      prime_array[j] = 0;
    }
  }
  return prime_array;
}
bool bit_search(int pattern, int N) {
  int cnt = 0;
  for (int bit = (0); bit < (N); bit++) {
    if (pattern & (1 << bit)) {
      cnt++;
    }
  }
  return true;
}
void initialize(void) {
  cout << fixed << setprecision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
}
