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