#include <bits/stdc++.h>
using namespace std;
const int maxn = 11;
int n, m, digit[maxn];
int main() {
  memset(digit, 0x3f3f3f3f, sizeof(digit));
  bool fl = true;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    digit[s] = min(digit[s], c);
  }
  for (int i = 1; i <= n; i++)
    if (digit[i] == 0x3f3f3f3f) digit[i] = 0;
  if (digit[1] == 0 && n > 1) fl = false;
  if (!fl)
    cout << "-1" << endl;
  else {
    for (int i = 1; i <= n; i++) cout << digit[i];
    cout << endl;
  }
  return 0;
}
