#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  long long result{-1};
  long long n, m;
  cin >> n >> m;
  vector<int> a(m, 0), b(m, 0);
  for (long long i = 0; i < long long(m); i++) {
    cin >> a[i] >> b[i];
  }
  if (n == 1) {
    for (long long i = 0; i <= long long(9); i++) {
      string s = to_string(i);
      for (long long j = 0; j < long long(m); j++) {
        if (((int)s[a[j] - 1] - (int)'0') != b[j]) break;
        if (j == m - 1) result = i;
      }
      if (result != -1) break;
    }
  } else if (n == 2) {
    for (long long i = 10; i <= long long(99); i++) {
      string s = to_string(i);
      for (long long j = 0; j < long long(m); j++) {
        if (((int)s[a[j] - 1] - (int)'0') != b[j]) break;
        if (j == m - 1) result = i;
      }
      if (result != -1) break;
    }
  } else if (n == 3) {
    for (long long i = 100; i <= long long(999); i++) {
      string s = to_string(i);
      for (long long j = 0; j < long long(m); j++) {
        if (((int)s[a[j] - 1] - (int)'0') != b[j]) break;
        if (j == m - 1) {
          result = i;
        }
      }
      if (result != -1) break;
    }
  }
  cout << result << endl;
  return 0;
}
