#include <bits/stdc++.h>
using namespace std;
int s[5];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    if (s[t1 - 1] > t2 || s[t1 - 1] == 0) s[t1 - 1] = t2;
  }
  if (n == 1) {
    cout << s[0];
    return 0;
  }
  if (s[0] == 0) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < n; i++) cout << s[i];
  return 0;
}
