#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<int> a(4, 10);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] > c) {
      a[s] = c;
    }
  }
  for (int i = 1; i < 4; i++) {
    if (a[1] == 10 || a[1] == 0) {
      ans = -1;
      break;
    }
    if (a[i] == 10) a[i] = 0;
    ans += a[i] * pow(10, 4 - i - 1);
  }
  cout << ans;
}
