#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> result(N);
  vector<bool> isChanged(N);
  for (int i = 0; i < (N); ++i) {
    result[i] = 0;
    isChanged[i] = false;
  }
  int s, c;
  for (int i = 0; i < (M); ++i) {
    cin >> s >> c;
    if (N == 1) {
      if (!isChanged[0]) {
        result[0] = c;
        isChanged[0] = true;
      } else {
        result[0] = min(result[0], c);
      }
    } else {
      if (s == 1 && !isChanged[0]) {
        result[0] = c;
        isChanged[0] = true;
      } else if (s == 1 && isChanged[0]) {
        result[0] = min(result[0], c);
      } else if (s > 1 && !isChanged[s - 1]) {
        result[s - 1] = c;
        isChanged[s - 1] = true;
      } else if (s > 1 && isChanged[s - 1]) {
        result[s - 1] = min(result[s - 1], c);
      }
    }
  }
  if (N == 1) {
    cout << result[0] << endl;
  } else {
    if (result[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      for (int i = 0; i < (N); ++i) {
        cout << result[i];
      }
      cout << endl;
    }
  }
}
