#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> con(m);
  for (int i = 0; i < m; i++) cin >> con[i].first >> con[i].second;
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    int num = i;
    vector<int> digit(n);
    for (int j = 0; j < n; j++) {
      digit[j] = num % 10;
      num /= 10;
    }
    reverse(digit.begin(), digit.end());
    bool flag = true;
    for (int j = 0; j < m; j++)
      if (digit[con[j].first - 1] != con[j].second) flag = false;
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
