#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int chk(vector<int> &a) {
  int n = a.size();
  for (int i = (0); i < (n); ++i) {
    cout << a.at(i);
  }
  cout << endl;
}
int gcd(int a, int b) {
  int tmp = a % b;
  a = b;
  b = tmp;
  if (b != 0) {
    return gcd(a, b);
  } else {
    return a;
  }
}
long long power(long long a, long long n) {
  if (n == 1) {
    return a;
  } else if (n & 1 == 1) {
    --n;
    return power(a, n) * a;
  } else {
    n = n >> 1;
    return power(a, n) * power(a, n);
  }
}
long long mod_power(long long a, long long n, long long p) {
  if (n == 1) {
    return a % p;
  } else if (n & 1 == 1) {
    --n;
    return (mod_power(a, n, p) * a) % p;
  } else {
    n = n >> 1;
    return (mod_power(a, n, p) * mod_power(a, n, p)) % p;
  }
}
long long mod_inv_fermat(long long a, long long p) {
  long long n = p - 2;
  return mod_power(a, n, p);
}
long long egcd(long long a, long long p, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return p;
  }
  long long d = egcd(p % a, a, y, x);
  x -= p / a * y;
  return d;
}
long long mod_inv(long long a, long long p) {
  long long x, y;
  egcd(a, p, x, y);
  return (x % p + p) % p;
}
int mod_combination(int n, int a, int p) {
  int m = min(a, n - a);
  int c = 0;
  long long up = 1;
  long long down = 1;
  while (c != m) {
    up = ((n - c) * up) % p;
    ++c;
    down = (down * c) % p;
  }
  return (up * mod_inv(down, p)) % p;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<short int> s(m), c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s.at(i) >> c.at(i);
  }
  string out(n, '0');
  bool check = false;
  short int tmp;
  for (int i = 0; i < m; ++i) {
    tmp = out.at(s.at(i) - 1) - '0';
    if (tmp == 0 || tmp == c.at(i)) {
      out.at(s.at(i) - 1) = c.at(i) + '0';
    } else {
      check = true;
      break;
    }
  }
  if (out.at(0) == '0') check = true;
  if (check)
    cout << "-1" << endl;
  else
    cout << out << endl;
}
