#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;
}
long long lmax(long long a, long long b) {
  if (a >= b) return a;
  return b;
}
long long lmin(long long a, long long b) {
  if (a >= b) return b;
  return a;
}
int digit(int n) {
  n /= 10;
  int res = 1;
  while (n) {
    res++;
    n /= 10;
  }
  return res;
}
int ketame(int x, int n) {
  for (long long i = 0; i < (digit(x) - n); ++i) {
    x /= 10;
  }
  return (x % 10);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (long long i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  for (long long i = 0; i < (1000); ++i) {
    if (n != digit(i)) continue;
    bool flag = true;
    for (long long j = 0; j < (m); ++j) {
      if (ketame(i, s[j]) != c[j]) flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
