#include <bits/stdc++.h>
using namespace std;
int a[10];
bool st[10];
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (!st[x]) {
      a[x] = y;
      st[x] = true;
    } else
      a[x] = min(a[x], y);
  }
  if (!a[1])
    cout << "-1" << endl;
  else {
    for (int i = 1; i <= n; i++) ans = ans * 10 + a[i];
    cout << ans << endl;
  }
  return 0;
}
