#include <bits/stdc++.h>
using namespace std;
void trace(int *intArray, int arraySize) {
  cout << intArray[0];
  for (int i = 1; i < arraySize; ++i) {
    cout << " " << intArray[i];
  }
  cout << "\n";
}
int main() {
  int n, m;
  cin >> n >> m;
  int *x = new int[n];
  int *flag = new int[n];
  for (int i = 0; i < n; ++i) {
    flag[i] = 0;
    x[i] = 10;
  }
  int s, c;
  for (int i = 0; i < m; ++i) {
    cin >> s;
    cin >> c;
    flag[s - 1] = 1;
    if (s == 1) {
      if (x[0] == 10 && c == 0) {
        x[0] = 0;
      } else if (x[0] == 0) {
        x[0] = c;
      } else if (x[0] > c) {
        x[0] = c;
      }
    } else {
      if (x[s - 1] > c) {
        x[s - 1] = c;
      }
    }
  }
  if (n == 1 && x[0] == 0) {
    cout << x[0];
    return 0;
  }
  if (flag[0] == 0 || x[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (flag[0] == 0) {
    x[0] = 1;
  }
  for (int i = 1; i < m; ++i) {
    if (flag[i] == 0) {
      x[i] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << x[i];
  }
  return 0;
}
