#include <bits/stdc++.h>
using namespace std;
namespace math {
long double PI = 3.14159265359;
long long step(long long n);
long long ncr(long long n, long long r);
long long npr(long long n, long long r);
long long gcm(long long a, long long b);
long long lcm(long long a, long long b);
long long step(long long n) {
  if (n <= 1) {
    return 1;
  } else {
    return n * step(n - 1);
  }
}
long long ncr(long long n, long long r) {
  for (long long i = 1; i < r; i++) {
    n *= n - i;
  }
  for (long long i = 1; i < r; i++) {
    r *= r - 1;
  }
  return n / r;
}
long long npr(long long n, long long r) {
  for (long long i = 1; i < r; ++i) {
    n *= n - 1;
  }
  return n;
}
long long gcm(long long a, long long b) {
  long long p = max(a, b);
  long long q = min(a, b);
  long long r;
  while (true) {
    if (p % q == 0) {
      return q;
    }
    r = p % q;
    p = q;
    q = r;
  }
}
}  // namespace math
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> A(m);
  long long max = -1;
  for (long long i = 0; i < m; i++) {
    cin >> A.at(i).first >> A.at(i).second;
    if (A[i].first > max) {
      max = A[i].first;
    }
  }
  vector<long long> B(max, -1);
  for (long long i = 0; i < m; i++) {
    long long p = A[i].first - 1;
    if (B[p] == -1) {
      B[p] = A[i].second;
    } else if (B[p] != A[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(B.begin(), B.end());
  long long ans;
  long long deg = 1;
  for (long long i = 0; i < max; i++) {
    if (B[i] == -1) {
      B[i] = 0;
    }
  }
  for (long long i = 0; i < max; i++) {
    ans += B[i] * deg;
    deg *= 10;
  }
  if (ans == 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
