#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int f(int t, int a, int m) {
  for (int i = 0; i < (m - a); ++i) {
    t /= 10;
  }
  return t % 10;
}
bool check(vector<int> s, vector<int> c, int t, int m) {
  bool flag = true;
  for (int i = 0; i < (m); ++i) {
    if (s[i] == 1 && c[i] == 0) {
      flag = false;
    }
    if (f(t, s[i], m) != c[i]) {
      flag = false;
    }
  }
  return flag;
}
int main() {
  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 t;
  for (t = 1; t < pow(10, n); ++t) {
    bool flag = check(s, c, t, m);
    if (flag) {
      cout << t << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
