#include <bits/stdc++.h>
using namespace std;
bool was[9];
void solve() {
  int n, m;
  cin >> n >> m;
  char s[n];
  for (int i = 0; i < n; i++) s[i] = '0';
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1) {
      if (s[x - 1] != '0') {
        s[x - 1] = min(y + '0', s[x - 1] + '0');
      } else {
        s[x - 1] = y + '0';
      }
    }
    if (!was[x]) {
      s[x - 1] = y + '0';
      was[x] = 1;
    } else {
      s[x - 1] = min(y + '0', s[x - 1] + '0');
    }
  }
  if (s[0] == '0') {
    cout << -1 << endl;
    return;
  }
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
}
int main() {
  solve();
  return (0);
}
