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