#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;
  int c, s;
  for (int i = 1; i <= m; i++) {
    cin >> c >> s;
    if (c == 1 && s) p = 1;
    a[c].push_back(s);
  }
  for (int i = 1; i <= n; i++) sort(a[i].begin(), a[i].end());
  if (!p) {
    if (n != 1)
      cout << -1 << endl;
    else
      cout << 0 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        for (auto v : a[1]) {
          if (v) {
            cout << v;
            break;
          }
        }
      } else {
        if (!a[i].size())
          cout << 0;
        else
          cout << a[i][0];
      }
    }
  }
  return 0;
}
