#include <bits/stdc++.h>
const int maxn = 2e1 + 7;
const long long mod = 998244353;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double EPS = 1e-8;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
int n, m, ans;
int s[10], c[10];
string ss;
bool flag = true;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &s[i], &c[i]);
    if (!isdigit(ss[s[i]]) || ss[s[i]] == c[i] + '0')
      ss[s[i]] = c[i] + '0';
    else
      flag = false;
  }
  if (ss[1] == '0' && n > 1) flag = false;
  if (!flag) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (!isdigit(ss[i]) && i > 1)
      ss[i] = '0';
    else if (!isdigit(ss[i]) && i == 1)
      ss[i] = '1';
  }
  for (int i = 1; i <= n; ++i) ans = ans * 10 + ss[i] - '0';
  printf("%d\n", ans);
}
