#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> digit(n, 0);
  for (int i = 0; i < m; i++) {
    int l, d;
    cin >> l >> d;
    if (digit[l - 1] > d || digit[l - 1] == 0) digit[l - 1] = d;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans = ans * 10 + digit[i];
  if (ans == 0)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
