#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
void quit(T a) {
  cout << a << endl;
  exit(0);
}
using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(3, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      quit(-1);
    }
    s--;
    s = 2 - s;
    if (a[s] != -1 && a[s] != c) {
      quit(-1);
    } else {
      a[s] = c;
    }
  }
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (a[i] == -1) {
      if (i == n - 1) {
        ans += 1 * (long long)pow(10, i);
      } else {
        continue;
      }
    } else {
      ans += a[i] * (long long)pow(10, i);
    }
  }
  cout << ans << endl;
  return 0;
}
