#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long int INF = 0x1fffffffffffffff;
const double eps = 1e-12;
void tostr(long long int x, string& res) {
  while (x) res += ('0' + (x % 10)), x /= 10;
  reverse((res).begin(), (res).end());
  return;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> t(m), c(m);
  for (int i = (0); i < (m); i++) scanf("%d%d", &t[i], &c[i]);
  for (int i = (0); i < (1000); i++) {
    string s;
    tostr(i, s);
    if (s.size() != n) continue;
    bool f = 1;
    for (int i = (0); i < (m); i++) {
      if (s[t[i] - 1] != c[i] + '0') f = 0;
    }
    if (f) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
