#include <bits/stdc++.h>
using namespace std;
set<int> s;
int A[5][5], B[5][5];
vector<int> a[5];
int main() {
  bool p = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) a[i].clear();
  int c, s;
  for (int i = 1; i <= m; i++) {
    cin >> c >> s;
    if (c == 1) {
      if (s > 0) {
        p = 1;
        a[c].push_back(s);
      }
    } else
      a[c].push_back(s);
  }
  if (p == 0) {
    if (n == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      cout << a[1][0];
    else {
      if (a[i].size()) {
        sort(a[i].begin(), a[i].end());
        cout << a[i][0];
      }
    }
  }
  return 0;
}
