#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using Graph = vector<vector<long long>>;
const long long MOD = 1000000007;
const long long INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
string toStrUp(string str) {
  char diff = 'A' - 'a';
  for (long long i = (0); i < (str.size()); ++i) str[i] += diff;
  return str;
}
string gCh(string str, long long key) { return str.substr(key, 1); }
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0;
  string s = "", t = "";
  cin >> n >> m;
  vector<ll> A(m);
  vector<ll> B(m);
  for (long long i = (0); i < (m); ++i) {
    cin >> A[i] >> B[i];
  }
  bool ok = true;
  if (n > 1) {
    for (long long i = (0); i < (m); ++i) {
      if (A[i] == 1 && B[i] == 0) ok = false;
    }
  }
  map<ll, ll> mp;
  for (long long i = (0); i < (9); ++i) {
    mp[i] = -1;
  }
  for (long long i = (0); i < (m); ++i) {
    if (mp[A[i]] == -1)
      mp[A[i]] = B[i];
    else {
      if (mp[A[i]] != B[i]) ok = false;
    }
  }
  if (m == 0 && n > 1) ok = false;
  if (!ok) {
    cout << -1 << '\n';
    return 0;
  }
  long long ans = 0;
  for (auto p : mp) {
    if (p.second == -1) continue;
    ans += p.second * pow(10, (n - p.first));
  }
  if (mp[1] == -1) {
    ans += pow(10, (n - 1));
  }
  if (m == 0 && n == 1) ans = 0;
  cout << ans << '\n';
}
