#include <bits/stdc++.h>
using namespace std;
int a[8];
int main() {
  for (int i = 0; i < 8; i++) a[i] = 0;
  int n, m;
  cin >> n >> m;
  int a1, b;
  for (int i = 0; i < m; i++) {
    cin >> a1 >> b;
    if (b == 0)
      a[a1] = 0;
    else if (a[a1] == 0)
      a[a1] = b;
    else {
      if (a[a1] > b) a[a1] = b;
    }
  }
  if (a[1] != 0) {
    for (int i = 1; i <= n; i++) cout << a[i];
  } else {
    if (n == 1)
      cout << a[1];
    else
      cout << "-1" << endl;
  }
}
