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