#include <bits/stdc++.h>
using namespace std;
const long long INF = long long(1e18) + 1;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (int i = 0; i < (m); ++i) {
    cin >> sc[i].first >> sc[i].second;
  }
  sort(sc.begin(), sc.end());
  vector<int> num(n, -1);
  for (int i = 0; i < (m); ++i) {
    if (num[sc[i].first - 1] == -1) {
      num[sc[i].first - 1] = sc[i].second;
    } else if (num[sc[i].first - 1] != sc[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (n); ++i) {
    if (num[i] == -1) {
      num[i] = 0;
    }
  }
  if (n == 1) {
    cout << num[0] << endl;
  } else if (n == 2) {
    if (num[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << num[0] << num[1] << endl;
    }
  } else {
    if (num[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else if (num[0] == 0 && num[1] == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << num[0] << num[1] << num[2] << endl;
    }
  }
  return 0;
}
