#include <bits/stdc++.h>
using namespace std;
struct node {
  int s, c;
} s[10];
bool cmp(node x, node y) { return x.s <= y.s; }
int main() {
  int m, n, v[10];
  memset(v, 0, sizeof(v));
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i].s >> s[i].c;
  bool f = true;
  sort(s, s + m, cmp);
  for (int i = 1; i < m; i++) {
    if (s[i].s == s[i - 1].s && s[i].c != s[i - 1].c) {
      f = false;
      break;
    }
  }
  if (s[0].s == 1 && s[0].c == 0 && n != 1) f = false;
  int ans = 0, t;
  if (s[0].s != 1) ans = ans + 1 * pow(10, n - 1);
  for (int i = 1; i < m; i++) {
    if (s[i].s == s[i - 1].s) v[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    if (v[i] == 1) continue;
    t = n - s[i].s;
    ans = ans + s[i].c * pow(10, t);
  }
  if (f)
    cout << ans;
  else
    cout << -1;
  return 0;
}
