#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes(int n, vector<int> &primes) {
  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;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) primes.push_back(p);
}
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
long long int power(long long int x, long long int y, long long int mod) {
  long long int temp;
  if (y == 0) return 1;
  temp = power(x, y / 2, mod);
  if (y % 2 == 0)
    return (temp * temp) % mod;
  else
    return (((x * temp) % mod) * temp) % mod;
}
vector<set<int> > g;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> m1;
  bool test = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x > n) test = 0;
    if (n > 1 && x == 1 && y == 0) test = 0;
    if (m1.find(x) != m1.end() && m1[x] != y) test = 0;
    m1[x] = y;
  }
  if (!test) {
    cout << "-1\n";
    return 0;
  }
  if (n == 1) {
    if (m1.find(1) != m1.end())
      cout << m1[1] << endl;
    else
      cout << "0\n";
  }
  for (int i = 1; i <= n; i++) {
    if (m1.find(i) != m1.end())
      cout << m1[i];
    else
      cout << "0";
  }
  cout << endl;
  return 0;
}
