#include <bits/stdc++.h>
using namespace std;
int a[10];
vector<int> b[4];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    b[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    int k = 10;
    for (int j = 0; j < b[i].size(); j++) {
      if (b[i][j] < k && b[i][j] != 0) k = b[i][j];
    }
    if (k != 10) a[i] = k;
  }
  if (a[1] == 0)
    puts("-1");
  else {
    int num = 0;
    for (int i = 1; i <= n; i++) num = num * 10 + a[i];
    if (num == 0)
      puts("-1");
    else
      cout << num << endl;
  }
  return 0;
}
