#include <bits/stdc++.h>
using namespace std;
long long INFl = (long long)1e+18 + 1;
int INF = 1e+9 + 1;
int main() {
  int N, M, s[6], c[6];
  int flag = 1;
  bool alre[5] = {};
  int now[5] = {};
  cin >> N >> M;
  for (int i = 0; i < (int)M; i++) {
    cin >> s[i] >> c[i];
    if (N != 0 && s[i] == 1 && c[i] == 0) flag = 0;
    if (alre[s[i]] == 1 && now[s[i]] != c[i])
      flag = 0;
    else {
      alre[s[i]] = 1;
      now[s[i]] = c[i];
    }
  }
  if (flag) {
    if (N == 1)
      cout << now[1] << endl;
    else if (N == 2) {
      if (now[1] == 0)
        cout << 10 + now[2] << endl;
      else
        cout << 10 * now[1] + now[2] << endl;
    } else {
      if (now[1] == 0)
        cout << 100 + 10 * now[2] + now[3] << endl;
      else
        cout << 100 * now[1] + 10 * now[2] + now[3] << endl;
    }
  } else
    cout << -1 << endl;
  return 0;
}
