#include <bits/stdc++.h>
using namespace std;
long long kaijo(long long n) {
  if (n == 0) return 1;
  return n * kaijo(n - 1);
}
long long POW(long long x, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1 == 1) {
      ans *= x;
    }
    x *= x;
    n >>= 1;
  }
  return ans;
}
long long combination(long long a, long long b) {
  long long tmp;
  tmp = kaijo(a) / (kaijo(b) * kaijo(a - b));
  return tmp;
}
vector<bool> is_prime;
void Eratosthenes(long long n) {
  is_prime.resize(n + 1, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (long long i = 2; i <= n; i++) {
    if (is_prime[i]) {
      for (long long j = i * i; j <= n; j++) {
        is_prime[j] = false;
      }
    }
  }
}
vector<long long> Prime;
void Prime_Enumeration(long long n) {
  Eratosthenes(n);
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      Prime.push_back(i);
    }
  }
}
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  long long r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return r;
}
long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  long long l = (a * b) / g;
  return l;
}
long long mod(long long a, long long m) { return (a % m + m) % m; }
long long extGCD(long long a, long long b, long long &p, long long &q) {
  if (b == 0) {
    p = 1;
    q = 0;
    return a;
  }
  long long d = extGCD(b, a % b, q, p);
  q -= a / b * p;
  return d;
}
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2,
                                      long long m2) {
  long long p, q;
  long long d = extGCD(m1, m2, p, q);
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2 / d);
  long long tmp = (b2 - b1) / d * p % (m2 / d);
  long long r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
const long long MOD = 1000000007;
int binary_search(long long *a, long long n, long long key) {
  long long right = n, left = -1;
  long long md = (right + left) / 2;
  while (right - left > 1) {
    if (a[md] <= key) {
      right = md;
    } else {
      left = md;
    }
    md = (right + left) / 2;
  }
  if (left == -1) return -1;
  return right;
}
bool isalpha(char s) {
  if (('A' <= s && s <= 'Z') || ('a' <= s && s <= 'z')) {
    return 1;
  } else {
    return 0;
  }
}
bool Isalpha(string s) {
  long long n;
  bool tmp = true;
  for (int i = 0; i < n; i++) {
    if (isalpha(s[i])) {
      tmp = false;
    }
  }
  return tmp;
}
string YES(bool a) { return a ? "YES" : "NO"; }
string Yes(bool a) { return a ? "Yes" : "No"; }
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> s(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i].first >> s[i].second;
  }
  sort(s.begin(), s.end());
  if (m == 0) {
    cout << pow(10, n - 1) << endl;
    return 0;
  }
  int ans[3];
  for (int i = 0; i < m - 1; i++) {
    if (m == 1) break;
    if (s[i].first == s[i + 1].first && s[i].second != s[i + 1].second) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (s[i].first == 1 && s[i].second == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    ans[s[i].first - 1] = s[i].second;
  }
  if (ans[0] == 0) {
    ans[0] = 1;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
