#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans1 = -1;
  int n, m, si, ci;
  cin >> n >> m;
  vector<int> ans(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> si >> ci;
    if (si - 1 > n) {
      cout << -1;
      exit(0);
    }
    if (si == 1) {
      if (ans[0] == 0)
        ans[0] = ci;
      else if (ans[0] > ci)
        ans[0] = ci;
    }
    if (ans[si - 1] == 0)
      ans[si - 1] = ci;
    else if (ans[si - 1] > ci)
      ans[si - 1] = ci;
  }
  if (ans[0] == 0) {
    if (n == 1)
      cout << 0;
    else
      cout << -1;
  } else
    for (int i = 0; i < n; i++) {
      cout << ans[i];
    }
  return 0;
}
