#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < (long long)m; i++) cin >> s[i] >> c[i];
  for (long long i = 0; i < (long long)m; i++) {
    if (n == 1 && s[i] == 1 && c[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < m - 1; i++) {
    for (long long j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (long long i = 0; i < (long long)m; i++)
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  long long res = 0;
  vector<bool> memo(10, false);
  for (long long i = 0; i < (long long)m; i++) {
    if (memo[s[i]] == true) continue;
    res += c[i] * pow(10, (n - s[i]));
    memo[s[i]] = true;
  }
  cout << res << endl;
}
