#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, x, y;
  cin >> a >> b;
  int arr[a];
  if (a == 1 && b == 0) {
    cout << "0\n";
    return 0;
  }
  for (int i = 0; i < a; i++) arr[i] = -1;
  for (int i = 0; i < b; i++) {
    cin >> x >> y;
    if (arr[x - 1] == -1 || arr[x - 1] == y)
      arr[x - 1] = y;
    else {
      cout << "-1\n";
      return 0;
    }
  }
  if (arr[0] == 0) {
    cout << "-1\n";
    return 0;
  }
  if (arr[0] == -1) arr[0] = 1;
  cout << arr[0];
  for (int i = 1; i < a; i++) {
    if (arr[i] == -1)
      cout << 0;
    else
      cout << arr[i];
  }
  cout << endl;
}
