#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<long long>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
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;
}
constexpr int inf = 1e9;
constexpr long long linf = 1e18;
constexpr long long mod = 1e9 + 7;
void solve();
int main() { solve(); }
void solve() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (long long i = 0; i < (long long)m; i++) cin >> s[i] >> c[i];
  int a[n];
  for (long long i = 0; i < (long long)n; i++) a[i] = 0;
  int flag = 0;
  int count[3];
  for (long long i = 0; i < (long long)3; i++) count[i] = 0;
  for (long long i = 0; i < (long long)m; i++) {
    if (a[s[i] - 1] == 0) {
      if (count[s[i] - 1] != 0 && c[i] != 0) {
        flag = -1;
      }
      a[s[i] - 1] = c[i];
      if (c[i] == 0) {
        count[s[i] - 1] = 1;
      }
    } else {
      if (a[s[i] - 1] != c[i]) {
        flag = -1;
      }
    }
  }
  if (flag == 0) {
    int sum = 0;
    int mod = 1;
    if (n == 1) {
      cout << a[0] << endl;
    } else {
      while (n > 1) {
        n--;
        sum += a[n] * mod;
        mod *= 10;
      }
      if (a[0] == 0) {
        cout << "-1" << endl;
      } else {
        sum += a[0] * mod;
        cout << sum << endl;
      }
    }
  } else {
    cout << flag << endl;
  }
}
