#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[10], c[10];
int flag = true;
int ans;
string t;
int main() {
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  int idx = (int)(pow(10, n - 1) + 0.5) - 1;
  for (int i = idx; i < idx * 10; i++) {
    t = to_string(i);
    flag = true;
    for (int j = 0; j < (m); j++) {
      int tint = t[s[j] - 1] - '0';
      if (tint != c[j]) flag = false;
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  if (flag)
    cout << ans;
  else
    cout << -1 << endl;
  return 0;
}
