#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1e9 + 7;
const long long INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      bool ok = 1;
      string t = to_string(i);
      for (int j = 0; j < (m); j++) {
        if (t[s[j] - 1] - '0' != c[j]) ok = 0;
      }
      if (ok) ans = i;
    }
  } else if (n == 2) {
    for (int i = 10; i < 100; i++) {
      bool ok = 1;
      string t = to_string(i);
      for (int j = 0; j < (m); j++) {
        if (t[s[j] - 1] - '0' != c[j]) ok = 0;
      }
      if (ok) ans = i;
    }
  } else if (n == 3) {
    for (int i = 100; i < 1000; i++) {
      bool ok = 1;
      string t = to_string(i);
      for (int j = 0; j < (m); j++) {
        if (t[s[j] - 1] - '0' != c[j]) ok = 0;
      }
      if (ok) ans = i;
    }
  }
  cout << ans << endl;
}
