#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[10], c[10], count[10][3] = {}, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
    if (count[s[i]][0] == 0) {
      count[s[i]][0]++;
      count[s[i]][1] = c[i];
    } else if (count[s[i]][0] == 1 && count[s[i]][1] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n == 3) {
    if (count[1][1] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    ans = count[1][1] * 100 + count[2][1] * 10 + count[3][1];
  } else if (n == 2) {
    if (count[1][1] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    ans = count[1][1] * 10 + count[2][1];
  } else if (n == 1) {
    ans = count[1][1];
  }
  cout << ans << endl;
}
