#include <bits/stdc++.h>
using namespace std;
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;
}
const long long INF = 1LL << 60;
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(int a, int b) { return (long long)a * b / gcd(a, b); }
int main() {
  int N, M;
  cin >> N >> M;
  int s[10], c[10];
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; i++) {
    int keta = 0, d[5];
    if (i <= 9) {
      keta = 1;
      d[3] = i;
      d[2] = 0;
      d[1] = 0;
    } else if (10 <= i && i <= 99) {
      keta = 2;
      d[3] = i % 10;
      d[2] = i / 10;
      d[1] = 0;
    } else {
      keta = 3;
      d[3] = i % 10;
      d[2] = (i / 10) % 10;
      d[1] = i / 100;
    }
    if (N != keta) continue;
    bool can = true;
    for (int j = 0; j < M; j++) {
      if (d[s[j]] != c[j]) {
        can = false;
      }
    }
    if (can) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
