#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
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;
}
int ctoi(char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
bool is_prime(const unsigned n) {
  switch (n) {
    case 0:
    case 1:
      return false;
    case 2:
    case 3:
      return true;
  }
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (unsigned i = 5; i * i <= n; i += 6) {
    if (n % i == 0) return false;
    if (n % (i + 2) == 0) return false;
  }
  return true;
}
map<long long, long long> mp;
long long primeFactorization(long long a) {
  long long i, sq;
  if (a % 2 == 0) {
    if (!mp.count(2)) {
      mp[2] = 1;
    } else {
      mp[2] += 1;
    }
    return primeFactorization(a / 2);
  }
  sq = sqrt(a);
  for (i = 3; i <= sq; i += 2) {
    if (a % i == 0) {
      if (!mp.count(i)) {
        mp[i] = 1;
      } else {
        mp[i] += 1;
      }
      return primeFactorization(a / i);
    }
  }
  if (a != 1) {
    if (!mp.count(a))
      mp[a] = 1;
    else {
      mp[a] += 1;
    }
  }
  return 0;
}
long long kaizyou(long long n) {
  if (n == 1) {
    return 1;
  } else {
    return (n * kaizyou(n - 1)) % 1000000007;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> d;
  bool ok = true;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (!d.count(s))
      d[s] = c;
    else if (d[s] == c)
      continue;
    else
      ok = false;
  }
  if (N == 1) {
    if (M == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (d.count(1) && d[1] == 0) ok = false;
  if (!ok)
    cout << -1 << endl;
  else {
    int a = pow(10, N - 1);
    for (int i = 1; i <= (int)(N); i++) {
      if (d.count(i)) {
        if (i == 1) {
          a = d[1] * pow(10, N - i);
        } else {
          a += d[i] * pow(10, N - i);
        }
      }
    }
    cout << a << endl;
  }
}
