#include <bits/stdc++.h>
using namespace std;
const int M = 6;
const int N = 1e3 + 10;
int solved() {
  int n, m;
  int s[M], c[M];
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int ans = -1;
  for (int i = 1000; i >= 0; i--) {
    bool ok = true;
    string S = to_string(i);
    for (int j = 0; j < m; j++) {
      if ((S[s[j] - 1] - '0') != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) ans = i;
  }
  if (n > 1 && m == 1 && c[0] == 0 && s[0] == 1) ans = -1;
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solved();
  return 0;
}
