#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
const int M = 1e9 + 7;
vector<int> dig[4];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    x--;
    dig[x].push_back(y);
  }
  for (int i = 0; i < n; i++) {
    if (dig[i].size() == 0) dig[i].push_back(0);
    sort(dig[i].begin(), dig[i].end());
  }
  if (dig[0].size() == 1 && dig[0][0] == 0) {
    return cout << -1, 0;
  }
  int num = dig[0][1];
  for (int i = 1; i < n; i++) {
    num = num * 10 + dig[i][0];
  }
  cout << num;
  return 0;
}
