#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int func(vector<int> &v) {
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    cnt = cnt + (v[i] * pow(10, v.size() - i - 1));
  }
  return cnt;
}
int main(void) {
  fast();
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  if (n == 1) {
    int a;
    int b = INT_MAX;
    for (int i = 0; i < m; i++) {
      cin >> a;
      if (b > a) {
        b = a;
      }
    }
    cout << b << "\n";
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (v[a - 1] == 0) {
      v[a - 1] = b;
    } else if (v[a - 1] > b) {
      v[a - 1] = b;
    }
  }
  if (v[0] == 0) {
    cout << -1 << "\n";
  } else {
    int cnt2 = 0;
    cnt2 = func(v);
    cout << cnt2 << "\n";
  }
}
