#include <bits/stdc++.h>
using namespace std;
void ng() {
  cout << -1 << endl;
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    cout << std::pow(10, n - 1) << endl;
    return 0;
  }
  if (n != 1) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && c[i] == 0) {
        ng();
        return 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = i; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        ng();
        return 0;
      }
    }
  }
  if (n == 1) {
    cout << c[0] << endl;
    return 0;
  }
  if (n == 2) {
    int ten = 0;
    int one = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1) {
        ten = c[i];
        continue;
      }
      if (s[i] == 2) {
        one = c[i];
        continue;
      }
    }
    cout << ten * 10 + one << endl;
    return 0;
  }
  if (n == 3) {
    int hundred = 0;
    int ten = 0;
    int one = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1) {
        hundred = c[i];
        continue;
      }
      if (s[i] == 2) {
        ten = c[i];
        continue;
      }
      if (s[i] == 3) {
        one = c[i];
        continue;
      }
    }
    cout << hundred * 100 + ten * 10 + one << endl;
    return 0;
  }
  return 0;
}
