#include <bits/stdc++.h>
using namespace std;
const int N = 200;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
void sieve() {
  bool prime[N + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= N; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= N; i += p) prime[i] = false;
    }
  }
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, a, b;
  cin >> n >> m;
  int A[n];
  bool check = true;
  memset(A, -1, sizeof(A));
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    if (A[a] == -1 || A[a] == b)
      A[a] = b;
    else
      check = false;
  }
  if (check == false)
    cout << -1;
  else {
    if (n == 1)
      cout << max(A[0], 0);
    else {
      if (A[0] <= 0) check = false;
      if (check == false)
        cout << "-1";
      else {
        for (int i = 0; i < n; i++) cout << max(0, A[i]);
      }
    }
  }
  return 0;
}
