#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> integer(n, 0);
  for (int i = 0; i < m; i++) {
    if (n > 1) {
      if (integer[s[i] - 1] == 0) {
        integer[s[i] - 1] = c[i];
      } else if (integer[s[i] - 1] != 0) {
        if (integer[s[i] - 1] <= c[i] || c[i] == 0) {
        } else
          integer[s[i] - 1] = c[i];
      }
    } else {
      sort(c.begin(), c.end());
    }
  }
  if (n > 1) {
    if (integer[0] == 0) {
      cout << "-1" << endl;
    } else {
      for (int i = 0; i < n; i++) {
        cout << integer[i];
      }
      cout << endl;
    }
  } else {
    cout << c[0] << endl;
  }
}
