#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[3] = {0};
  cin >> n >> m;
  if (m == 0) {
    cout << "-1\n";
    return 0;
  } else {
    int s, c, i, ans;
    for (i = 0; i < m; i++) {
      cin >> s >> c;
      a[s - 1] = c;
    }
    ans = a[0] * 100 + a[1] * 10 + a[2];
    if (n == 3 && ans >= 100)
      cout << ans << endl;
    else if (n == 2 && ans >= 10 && ans < 100)
      cout << ans << endl;
    else if (n == 1 && ans < 10)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
