#include <bits/stdc++.h>
using namespace std;
using ll = long long;
unsigned long long GCD(unsigned long long a, unsigned long long b) {
  if (a % b == 0) {
    return b;
  } else {
    return GCD(b, a % b);
  }
}
unsigned long long GCD(vector<unsigned long long> v) {
  for (auto i = 0; i < (long long)v.size() - 1; i++) {
    v[i - 1] = GCD(v[i - 1], v[i]);
  }
  return v[(long long)v.size() - 1];
}
unsigned long long LCM(unsigned long long x, unsigned long long y) {
  unsigned long long gcd = GCD(x, y);
  return (x / gcd * y);
}
unsigned long long LCM(vector<unsigned long long> v) {
  for (long long i = 0; i < (long long)v.size() - 1; i++) {
    v[i - 1] = LCM(v[i - 1], v[i]);
  }
  return v[(long long)v.size() - 1];
}
vector<long long> CUSUM(vector<long long> v) {
  int n = v.size();
  vector<long long> cusum(n);
  cusum[0] = v[0];
  for (ll i = 1; i < n; i += 1) {
    cusum[i] = v[i] + cusum[i - 1];
  }
  return cusum;
}
long long partSum(vector<long long> &&v, long long left, long long right) {
  return (v[right] - v[left]);
}
const int MAX = 800000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool isPrime(long long n) {
  if (n <= 1) {
    return false;
  } else if (n == 2) {
    return true;
  } else if (n % 2 == 0) {
    return false;
  } else {
    for (ll i = 3; i < sqrt(n) + 1; i += 2) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  }
}
int solve1() {
  int n, m;
  string ans = "000";
  bool ok = true;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (ll i = 0; i < m; i += 1) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (ll i = 0; i < m; i += 1) {
    if (ok) {
      if (ans[s[i]] == '0' || ans[s[i]] == c[i]) {
        ans[s[i]] = c[i];
      } else {
        ans = "-1";
        ok = false;
      }
    }
  }
  if (to_string(stoi(ans)).length() != n) {
    ans = "-1";
  }
  return stoi(ans);
}
int main(void) {
  cout << solve1() << endl;
  return 0;
}
