#include <bits/stdc++.h>
using namespace std;
set<int> s;
int A[5][5], B[5][5];
vector<int> a[5];
int main() {
  int a[4] = {10, 10, 10, 10};
  int n, m;
  cin >> n >> m;
  int s, c;
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    if (s == 1 && c > 0) a[1] = min(a[1], c);
    if (s == 2) a[2] = min(a[2], c);
    if (s == 3) a[3] = min(a[3], c);
  }
  if (a[1] == 10) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (i == 1) cout << a[1];
      if (i == 2) {
        if (a[2] == 10)
          cout << 0;
        else
          cout << a[2];
      }
      if (i == 3) {
        if (a[3] == 10)
          cout << 0;
        else
          cout << a[3];
      }
    }
  }
  return 0;
}
