#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int s[10];
  char c[10];
  for (int i = 0; i < (M); ++i) cin >> s[i] >> c[i];
  string s_num;
  int flag = 0;
  queue<int> que;
  for (int i = 0; i < 1000; i++) {
    s_num = to_string(i);
    flag = 1;
    for (int j = 0; j < (M); ++j) {
      if (s_num[s[j] - 1] != c[j]) flag = 0;
    }
    if (i == 0 && N != 1) flag = 0;
    if (flag) que.push(i);
  }
  if (que.size())
    cout << que.front() << endl;
  else
    cout << -1 << endl;
  return 0;
}
