#include <bits/stdc++.h>
using namespace std;
char is_prime[100010];
int prime[100000];
bool check(int j, int n, vector<int> &s, vector<int> &c) {
  ostringstream oss;
  oss << j;
  string buf = string(oss.str());
  for (int i = 0; i < n; i++) {
    if (buf[s[i] - 1] != '0' + c[i]) return false;
  }
  return true;
}
int main() {
  int n, m;
  char isUpdate[3] = {0};
  cin >> n >> m;
  vector<int> s(m), c(m);
  int answer = -1;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int start = (n == 1 ? 0 : (n == 2 ? 10 : 100));
  int end = (n == 1 ? 9 : (n == 2 ? 99 : 999));
  for (int j = start; j <= end; j++) {
    if (check(j, n, s, c)) {
      answer = j;
      break;
    }
  }
  cout << answer << endl;
  return 0;
}
