#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int dig(int n) {
  if (n == 0) return 1;
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}
int d(int i, int j) {
  if (i == 0) {
    return 0;
  } else if (i == 1) {
    return 100 * j;
  } else if (i == 2) {
    return 10 * j;
  } else {
    return j;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> data(m, pair<int, int>(m, 0));
  for (int i = 0; i < (m); ++i) {
    cin >> data.at(i).first >> data.at(i).second;
  }
  sort(data.begin(), data.end());
  int res = 0;
  for (int i = 0; i < (pow(10, n) + 1); ++i) {
    string s = to_string(i);
    for (int j = 0; j < (m); ++j) {
      int kurai = data.at(j).first - 1;
      int check = s[kurai] - 48;
      if (check != data.at(j).second) {
        break;
      }
      if (j == m - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
