#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const ll MOD = 1e+9 + 7;
int n, m;
int memo[4][1010][2];
int node[1010][2];
vector<int> exist[1010];
int assign[1010];
bool visit[1010];
vector<int> g[1010];

int sign(int x) {
  if (x > 0) { return 1; }
  if (x < 0) { return -1; }
  return 0;
}
int OK(int index) {
  int x = abs(node[index][0]);
  int y = abs(node[index][1]);
  int ret = 0;
  if (assign[x] != 0) { ret |= sign(assign[x]) == sign(node[index][0]); }
  if (assign[y] != 0) { ret |= sign(assign[y]) == sign(node[index][1]); }
  return ret;
}

int calc(int sval, int from, int parent, int start) {
  visit[from] = true;
  int ok = OK(from);
  if (memo[sval][from][ok] != -1) { return memo[sval][from][ok]; }
  ll ret = 0;
  if (g[from].size() == 1) { return ok ? 2 : 1; }
  if (g[from].size() == 2 && g[from][0] == g[from][1]) {
    return ok ? 1 : 0;
  }
  FORIT(it, g[from]) {
    int to = *it;
    if (to == parent) { continue; }
    if (to == start) {
      ret = ok ? 1: 0;
      continue;
    }
    int target = -1;
    REP(i, 2) {
      REP(j, 2) {
        int x = abs(node[from][i]);
        int y = abs(node[to][j]);
        if (x == y) { target = x; }
      }
    }
    assert(assign[target] == 0);
    assign[target] = 1;
    ret = (ret + OK(from) * calc(sval, to, from, start)) % MOD;
    assign[target] = -1;
    ret = (ret + OK(from) * calc(sval, to, from, start)) % MOD;
    assign[target] = 0;
  }
  return memo[sval][from][ok] = ret;
}

int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    MEMSET(memo, -1);
    MEMSET(assign, 0);
    MEMSET(visit, false);
    REP(i, 1010) {
      exist[i].clear();
      g[i].clear();
    }
    ll ans = 1;
    {
      int cnt = 0;
      REP(i, m) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x == y) { continue; }
        if (abs(x) == abs(y)) { ans = (ans * 2) % MOD; continue; }
        node[cnt][0] = x;
        node[cnt][1] = y;
        exist[abs(x)].push_back(cnt);
        exist[abs(y)].push_back(cnt);
        cnt++;
      }
      m = cnt;
    }
    REP(i, 1010) {
      if ((int)exist[i].size() <= 1) { continue; }
      int from = exist[i][0];
      int to = exist[i][1];
      g[from].push_back(to);
      g[to].push_back(from);
    }
    REP(iter, 3) {
      REP(i, m) {
        if (visit[i]) { continue; }
        if ((int)g[i].size() != iter) { continue; }
        visit[i] = true;
        if (g[i].empty()) { ans = (ans * 3) % MOD; continue; }
        ll lans = 0;
        REP(j, 4) {
          int x = abs(node[i][0]);
          int y = abs(node[i][1]);
          assign[x] = (j & 1) * 2 - 1;
          assign[y] = ((j >> 1) & 1) * 2 - 1;
          lans = (lans + OK(i) * calc(j, g[i][0], i, i)) % MOD;
        }
        ans = (ans * lans) % MOD;
      }
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 0