#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long power_without_mod(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
bool comparep(pair<long long, long long> i1, pair<long long, long long> i2) {
  return (i1.second < i2.second);
}
long long modInverse(long long a) { return power(a, 1000000007 - 2); }
vector<long long> spf;
void seive(int n) {
  for (int i = 1; i <= n; i++) spf[i] = i;
  for (int i = 2; i <= n; i++) {
    for (int j = i * i; j <= n; j += i) {
      if (spf[j] == j) {
        spf[j] = i;
      }
    }
  }
}
long long primesum(long long a) {
  int curr = spf[a];
  int count = 0;
  long long prod = 1;
  while (a != 1) {
    count++;
    a /= spf[a];
    if (spf[a] != curr) {
      prod *= (count + 1);
      count = 0;
      curr = spf[a];
    }
  }
  return prod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  for (long long z = 0; z < t; z++) {
    long long n, m;
    cin >> n >> m;
    vector<int> number(n, -1);
    int flag = 0;
    for (long long i = 0; i < m; i++) {
      long long p, q;
      cin >> p >> q;
      if (number[p - 1] == -1 || number[p - 1] == q)
        number[p - 1] = q;
      else
        flag = 1;
    }
    if (flag || (number[0] == 0 && n != 1))
      cout << "-1";
    else {
      cout << ((number[0] == -1) ? 1 : number[0]);
      for (int i = 1; i < n; i++) cout << ((number[i] == -1) ? 0 : number[i]);
    }
  }
}
