#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool isPrime(long long x) {
  long long i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0) return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0) return 0;
  return 1;
}
int digsum(long long n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
int dignum(long long n) {
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}
long long stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}
long long ka(long long i) {
  long long res = 1;
  while (i > 0) {
    res = res * i;
    i--;
  }
  return res;
}
long long ncr(long long x, long long y) {
  long long a = x;
  long long b = 1;
  if (y > (x / 2)) {
    y = x - y;
  }
  for (long long i = 1; i < y; i++) {
    a *= x - i;
    b *= i + 1;
  }
  return a / b;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int ans[n];
  for (long long(i) = 0; (i) < (m); (i)++) {
    cin >> s[i] >> c[i];
  }
  for (long long(i) = 0; (i) < (n); (i)++) {
    ans[i] = 10;
  }
  for (long long(i) = 0; (i) < (m); (i)++) {
    if (ans[s[i] - 1] == 10) {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long(i) = 0; (i) < (n); (i)++) {
    if (ans[i] == 10) {
      ans[i] = 0;
    }
  }
  if (n == 3 and ans[2] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 2 and ans[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long(i) = 0; (i) < (n); (i)++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
