#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long inf = 1e18 + 1;
const long long mod = 1e9 + 7;
void print(long long a[], long long n) {
  for (long long i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
long long power(long long x, long long y, long long M = inf) {
  long long ans = 1;
  x %= M;
  while (y) {
    if (y & 1) ans = (x * ans) % M;
    x = (x * x) % M;
    y >>= 1;
  }
  return ans;
}
long long modInverse(long long n) { return power(n, mod - 2, mod); }
inline long long mul(long long a, long long b) { return (a * b) % mod; }
inline long long sub(long long a, long long b) {
  long long c = a - b;
  if (c < 0) c += mod;
  return c;
}
inline long long add(long long a, long long b) {
  long long c = a + b;
  if (c > mod) c -= mod;
  return c;
}
inline long long divi(long long a, long long b) {
  return mul(a, modInverse(b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  long long s[m], c[m];
  vector<long long> v(n, 10);
  long long flag = 0;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (v[s[i] - 1] == 10) {
      v[s[i] - 1] = c[i];
    } else if (v[s[i] - 1] != c[i]) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (v[0] == 10) {
    if (n == 1) v[0] = 0;
    if (n != 1) v[0] = 1;
  }
  if (v[0] == 0 && n != 1) {
    cout << -1 << "\n";
    return 0;
  }
  long long ans = 0;
  for (int j = 0; j < n; j++) {
    ans = ans * 10 + v[j];
  }
  cout << ans << "\n";
  return 0;
}
