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